/*
package com.sitech.order.action;

import com.opensymphony.xwork2.ActionSupport;
import com.sitech.agents.model.EshopAgentsInfo;
import com.sitech.agents.service.EshopAgentsInfoService;
import com.sitech.common.base.Cantants;
import com.sitech.common.util.*;
import com.sitech.jbpm.util.JbpmType;
import com.sitech.logistics.VO.JDLogisticsResp;
import com.sitech.logistics.VO.PreSortResult;
import com.sitech.logistics.model.EshopDistribution;
import com.sitech.logistics.model.EshopDistributionItem;
import com.sitech.logistics.model.EshopOrderRecipient;
import com.sitech.logistics.model.OrderPushOut;
import com.sitech.logistics.service.EshopDistributionItemService;
import com.sitech.logistics.service.EshopDistributionService;
import com.sitech.logistics.service.EshopOrderRecipientService;
import com.sitech.order.model.EshopOrder;
import com.sitech.order.model.EshopOrderAuxiliaryInfo;
import com.sitech.order.model.EshopOrderInfoExcel;
import com.sitech.order.model.EshopOrderItem;
import com.sitech.order.model.SmallWhiteBatchSenderHistoryInfo;
import com.sitech.order.model.SmallWhiteOrder;
import com.sitech.order.service.EshopOrderAuxiliaryInfoService;
import com.sitech.order.service.EshopOrderItemService;
import com.sitech.order.service.EshopOrderService;
import com.sitech.order.service.SmallWhiteCheckFailOrderService;
import com.sitech.order.service.SmallWhiteOrderService;
import com.sitech.order.service.impl.SmallWhiteOrderServiceImpl;
import com.sitech.redis.RedisCache;
import com.sitech.redis.RedisSequenceUtils;
import com.sitech.systemmanage.model.EshopAdmin;
import com.sitech.uim.api.EshopCardInfoMapper;
import com.sitech.uim.model.EshopCardInfo;
import com.sitech.uim.service.UimInfoService;
import jxl.CellType;
import jxl.DateCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.httpclient.HttpsURL;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Qualifier;
import sitech.www.frame.jdbc.SqlDelete;
import sitech.www.frame.jdbc.SqlInsert;
import sitech.www.frame.jdbc.SqlQuery;
import sitech.www.frame.jdbc.SqlUpdate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SmallWhireCardOrderAtion extends ActionSupport {

    */
/**
     *
     *//*

    private static final long serialVersionUID = 1L;
    private static final ResourceBundle bundle = ResourceBundle.getBundle("interface");
    private EshopAdmin eshopAdmin;
    private String msg;//返回信息
    private File upfile; //上传文件对象
    private String upfileFileName; //文件名称
    private String upfileContentType; //文件类型
    private String inputPath;
    private String pubCode; //宣传编码 package表中的bub_code
    private String orderId;
    private String externalOrderId;
    private String startTime;
    private String endTime;
    private String linkPhone;
    private String flag;
    private String checkFlag;

    private int page;
    private int pageSize = PaginationSupport.DEFAULT_MAX_PAGE_ITEMS;
    private PaginationSupport ps;

    private static final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static final TimeZone zone = TimeZone.getTimeZone("GMT");

    private String templateUrl;
    private String logisticsAgentsId;//物流商 16EMS 17京东
    private String send_num;//发货数量
    private String productType;//快递类型
    private String contentsAttribute;//内件性质
    private String ICCIDStart;
    private String ICCIDEnd;
    private List<Map<String, Object>> xbOrderToDeliveryList;
    private JSONArray deliveryjsonArray;
    private List<SmallWhiteBatchSenderHistoryInfo> xbSenderHistoryList;
    private String batchId;//批次id
    private Map<String,String> productNameInfoMap;//产品名集合 小白用
    private String product_name;
    private Date startDate = null;//查询条件
    private Date endDate = null;
    private String chooseSum;//发货订单数
    private String chooseParams;//发货订单号明细
    private int totalCount;//查询结果数
    private String if_send_jd;
    private String message;
    private String orderBy;
    private String if_send_ems;
    private String now_actual_send_sum;
    private Map<String,String> channelNameInfoMap;//渠道名集合 小白用
    private Map<String,String> pubCodeInfoMap;//渠道名集合 小白用
    private String channel_name;
    private String channel_id;
    private List<SmallWhiteBatchSenderHistoryInfo> xbSenderOrderSee;

    private String lsjg;//揽收机构
    private String ysr;//验视人

    @Resource
    private SmallWhiteOrderService smallWhiteOrderService;
    @Resource
    @Qualifier("SmallWhiteCheckFailOrderService")
    private SmallWhiteCheckFailOrderService smallWhiteCheckFailService;
    @Resource
    private EshopAgentsInfoService eshopAgentsInfoService;
    @Resource
    private EshopDistributionService eshopDistributionService;
    @Resource
    private EshopOrderService eshopOrderService;
    @Resource
    private EshopOrderItemService eshopOrderItemService;
    @Resource
    private EshopOrderRecipientService eshopOrderRecipientService;
    @Resource
    private EshopOrderAuxiliaryInfoService eshopOrderAuxiliaryInfoService;
    @Resource
    private EshopDistributionItemService eshopDistributionItemService;
    @Resource
    private UimInfoService uimInfoService;
    @Resource
    private EshopCardInfoMapper eshopCardInfoMapper;

    */
/**
     * 进入订单管理页面，查询订单
     * @return
     *//*

    public String qrySmallWhiteOrder(){
        Map paramMap=new HashMap<String, String>();
        try{
            eshopAdmin = Cantants.getEshopAdmin();
            if(eshopAdmin==null){
                msg="请先进行登录，或确认工号是否正确";
                System.out.println("qrySmallWhiteOrder =="+ eshopAdmin + ":" + msg);
                return ERROR;
            }
            if(StringUtils.isBlank(eshopAdmin.getChannelIdStr())){
                msg="工号渠道不能为空";
                System.out.println("qrySmallWhiteOrder =="+ eshopAdmin.getUserName() + ":" + msg);
                return ERROR;
            }
            paramMap.put("startTime", startTime);
            paramMap.put("endTime", endTime);
            paramMap.put("orderId", orderId);
            paramMap.put("externalOrderId", externalOrderId);
            paramMap.put("linkPhone", linkPhone);
            paramMap.put("flag", flag);
            paramMap.put("channelIdStr", eshopAdmin.getChannelIdStr());
            paramMap.put("checkFlag", checkFlag);
            paramMap.put("channelIdStr", eshopAdmin.getChannelIdStr());
            if ("2".equals(checkFlag)) {
                ps=smallWhiteCheckFailService.selSmallWhiteCheckFailOrder(page, pageSize, paramMap);
            }else {
                ps=smallWhiteOrderService.selSmallWhiteOrder(page==0?1:page, pageSize, paramMap);

            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return SUCCESS;
    }

    public String importOrder(){
        msg="";
        int importFailed = 0;
        int importSuccess = 0;
        //拦截次数
        int checkFiledCount = 0;
        //被拦截的电话
        String checkFiledPhone="";
        String Checkmsg="";
        String failedMsg="";
        eshopAdmin = Cantants.getEshopAdmin();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("import smallWhiteCardOrder with excel=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        if(StringUtils.isBlank(eshopAdmin.getChannelIdStr())){
            msg="工号渠道不能为空";
            System.out.println("import smallWhiteCardOrder with excel=="+ eshopAdmin.getUserName() + ":" + msg);
            return ERROR;
        }
        String channelId = eshopAdmin.getChannelIdStr();
        if(channelId.contains(";")){
            channelId = channelId.substring(0,eshopAdmin.getChannelIdStr().length()-1);
        }
        StringBuffer sb = new StringBuffer();
        sb.append("select t.channel_name ");
        sb.append(" from eshop_channel_management t where 1=1");
        sb.append(" and t.channel_id = '"+ channelId+"'");
        System.out.println("import smallWhiteCardOrder with excel查询渠道=="+sb.toString());
        List channelIdlist = SqlQuery.findList(sb.toString());
        if(channelIdlist==null || channelIdlist.size()==0){
            msg="未查到对应的商户名称";
            System.out.println("import smallWhiteCardOrder with excel==" + msg);
            return ERROR;
        }
        String[] channelArr=(String[]) channelIdlist.get(0);

        String channelName=channelArr[0];


        String fileType = upfileFileName.substring(upfileFileName.lastIndexOf(".")+1,upfileFileName.length());
        System.out.println("import smallWhiteCardOrder with excel==文件名：" + upfileFileName);
        System.out.println("import smallWhiteCardOrder with excel==File：" + upfile);
        if (!fileType.equals("xls")){
            msg="导入失败，文件类型不正确!";
            System.out.println("import smallWhiteCardOrder with excel==" + msg);
            return ERROR;
        }
        List<SmallWhiteOrder> list=new ArrayList<SmallWhiteOrder>();
        try{
            InputStream inputStream = new FileInputStream(upfile);
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet rs = null;
            int countSheets = rwb.getNumberOfSheets();
            if (countSheets < 1){
                rwb.close();
                msg = "该订单文件没有数据";
                System.out.println("import smallWhiteCardOrder with excel==" + msg);
                return ERROR;
            }
            rs = (Sheet)rwb.getSheet(0); // 仅取第一页
            int rowCount = rs.getRows(); //行数
            int colCount = rs.getColumns(); //列数
            if(rowCount<2){
                msg = "文件中没有订单记录，请确认";
                System.out.println("import smallWhiteCardOrder with excel==" + msg);
                return ERROR;
            }
            if(colCount<9){
                msg = "文件模板不正确，请确认";
                System.out.println("import smallWhiteCardOrder with excel==" + msg);
                return ERROR;
            }
            int realRowCount=0;
            List<String> realList=new ArrayList<String>();
            for (int irow = 1; irow < rowCount; irow++){
                boolean isBlankRow=true;
                for (int j = 0; j < colCount; j++) {
                    if (StringUtils.isNotBlank(rs.getCell(j, irow).getContents())) {
                        isBlankRow=false;
                        break;
                    }
                }
                if (!isBlankRow) {
                    String linkPhone = ((Sheet) rs).getCell(3, irow).getContents().trim();
                    if(StringUtils.isBlank(linkPhone)){
                        msg+="第"+irow+"行，收货电话为空，请修改数据后重新导入；</br>";
                        System.out.println("import smallWhiteCardOrder with excel"+msg);
                    }else{
                        // 校验收货电话号码合法性

                        if (!checkLinkPhone(linkPhone)) {
                            msg+="第"+irow+"行，收货电话不合法，请修改数据后重新导入；</br>";
                            System.out.println("import smallWhiteCardOrder with excel"+msg);
                        }

                    }
                    try {
                        // 获取Excel表格里的日期
                        DateCell  sendTime = (DateCell) (((Sheet) rs).getCell(9, irow));
                        String dateStr = sdf.format(sendTime.getDate());
                        //调用校验方法，返回true为通过，false为不通过
                        if (!isValidDate(dateStr)) {
                            msg+="第"+irow+"行，时间格式不合法，请修改数据后重新导入；</br>";
                            System.out.println("import smallWhiteCardOrder with excel"+msg);
                        }

                    } catch (Exception e) {
                        msg+="第"+irow+"行，时间格式不合法，请修改数据后重新导入；</br>";
                    }

                    ++realRowCount;
                    realList.add(linkPhone);
                }
            }
            if (StringUtil.isNotBlank(msg)) {
                return ERROR;
            }
            System.out.println("import smallWhiteCardOrder with excel, has " + realRowCount + " lines and " + colCount + " columns");
            if(realRowCount<1 && realRowCount>3000){
                msg="导入数据条数应在0~3000条，请确认！";
                System.out.println("import smallWhiteCardOrder with excel=="+msg);
                return ERROR;
            }
            if(StringUtils.isNotBlank(msg)){
                System.out.println("import smallWhiteCardOrder with excel=="+msg);
                return ERROR;
            }
            for (int irow = 1; irow <= realRowCount; irow++){
                HashMap< String, Object> map =new HashMap<String, Object>();
                SmallWhiteOrder swOrder=new SmallWhiteOrder();
                String externalOrderId = ((Sheet) rs).getCell(1, irow).getContents().trim();
                swOrder.setExternalOrderId(externalOrderId);
                String productName = ((Sheet) rs).getCell(2, irow).getContents().trim();
                swOrder.setProductName(productName);
                String linkPhone = ((Sheet) rs).getCell(3, irow).getContents().trim();
                swOrder.setLinkPhone(linkPhone);
                String receiver = ((Sheet) rs).getCell(4, irow).getContents().trim();
                swOrder.setReceiver(receiver);
                String province = ((Sheet) rs).getCell(5, irow).getContents().trim();
                province=province.replaceAll("[\\t\\n\\r]", "");
                swOrder.setProvinceName(province);
                String city = ((Sheet) rs).getCell(6, irow).getContents().trim();
                city=city.replaceAll("[\\t\\n\\r]", "");
                swOrder.setCityName(city);
                String county = ((Sheet) rs).getCell(7, irow).getContents().trim();
                county=county.replaceAll("[\\t\\n\\r]", "");
                swOrder.setCountyName(county);
                String detailAddress = ((Sheet) rs).getCell(8, irow).getContents().trim();
                detailAddress=detailAddress.replaceAll("[\\t\\n\\r]", "");
                swOrder.setAddress(province+city+county+detailAddress);
                if(((Sheet) rs).getCell(9, irow).getType()==CellType.DATE){
                    DateCell  sendTime = (DateCell) (((Sheet) rs).getCell(9, irow));
                    swOrder.setSendTime(sendTime.getDate());
                    System.out.println("import smallWhiteCardOrder with excel时间=="+sdf.format(sendTime.getDate()));
                    sdf.setTimeZone(zone);
                    swOrder.setSendTimeStr(sdf.format(sendTime.getDate()));
                    System.out.println("import smallWhiteCardOrder with excel时间=="+sdf.format(sendTime.getDate()));
                }else{
                    String sendTime = ((Sheet) rs).getCell(9, irow).getContents().trim();
                    swOrder.setSendTime(sdf.parse(sendTime));
                    swOrder.setSendTimeStr(sendTime);
                }
                String name = ((Sheet) rs).getCell(10, irow).getContents().trim();
                swOrder.setName(name);
                String idcardCode = ((Sheet) rs).getCell(11, irow).getContents().trim();
                swOrder.setIdcardCode(idcardCode);
                String remark = ((Sheet) rs).getCell(12, irow).getContents().trim();
                swOrder.setRemark(remark);

                swOrder.setChannelId(channelId);
                swOrder.setChannelName(channelName);
                swOrder.setId(UUID.randomUUID().toString().replaceAll("-",""));
                //拼装地址
                String address="";
                if(StringUtils.isNotBlank(detailAddress)){
                    address=province+city+county+detailAddress;
                }

                Map<String, Object> checkMap =smallWhiteCheck(irow, channelId,linkPhone, address, idcardCode, name);
                String checkCode =(String) checkMap.get("checkCode");
                String checkName =(String) checkMap.get("checkName");
                if (!"0".equals(checkCode)) {
                    Checkmsg += (String) checkMap.get("msg");
                }
                //数据入库操作
                map=smallWhiteCardInDatabase(swOrder,checkCode,checkName);
                Boolean bSaveOk=(Boolean) map.get("bSaveOk");
                Boolean bcheckOk=(Boolean) map.get("bCheckOk");

                list.add(swOrder);
                if (!bSaveOk){
                    importFailed += 1;
                    failedMsg += linkPhone+",";
                }else{
                    importSuccess += 1;
                    if (!bcheckOk) {
                        checkFiledCount += 1;
                        checkFiledPhone+= linkPhone+",";
                    }
                }
            }
        }catch(Exception e){
            msg="文件格式异常，请确认";
            System.out.println("import smallWhiteCardOrder with excel 异常==" + e.getMessage());
            e.printStackTrace();
            return ERROR;
        }

        //记录日志
        //有数据导入失败的情况下
        if(StringUtils.isNotBlank(failedMsg)){
            failedMsg=failedMsg.substring(0,failedMsg.length()-1);
            //有数据导入失败且有数据校验不通过
            if (StringUtils.isNotBlank(Checkmsg) ){
                msg = "共"+list.size()+"条数据,"
                        + "导入成功" + importSuccess + "条。"
                        + "导入失败" +importFailed + "条。"
                        + "导入失败的号码为："+failedMsg+"。"
                        +"</br>导入成功的数据中有"+checkFiledCount+"条数据未通过省安防拦截校验，已经全部入库，无需再重复导入。"
                        +"</br>拦截原因：</br>"+Checkmsg
                ;
            } else {
                //有数据导入失败且数据全部校验通过
                msg = "共"+list.size()+"条数据,导入成功" + importSuccess + "条,"
                        + "导入失败" +importFailed + "条。"
                        + "导入失败的号码为："+failedMsg+"。"
                ;
            }

            return ERROR;
        }else{
            //没有数据导入失败，但是有数据没通过校验
            if (StringUtils.isNotBlank(Checkmsg) ){
                msg = "共"+list.size()+"条数据,导入成功" + importSuccess + "条。"
                        + "导入失败" +importFailed + "条。"
                        +"</br>导入成功的数据中有"+checkFiledCount+"条数据未通过省安防校验，已经全部入库，无需再重复导入。"
                        +"</br>拦截原因：</br>"+Checkmsg
                ;
                return ERROR;

            }else {
                //所有数据导入成功且全部通过校验。
                msg = "共"+list.size()+"条数据,导入成功" + importSuccess + "条,"
                        + "导入失败" +importFailed + "条。";
            }

        }
        System.out.println("import smallWhiteCardOrder with excel==" + msg);
        return SUCCESS;
    }

    */
/**
     * 小白订单入库操作
     * @param smWhiteOrder
     * @return
     *//*

    public HashMap<String, Object> smallWhiteCardInDatabase(SmallWhiteOrder smWhiteOrder,String checkCode,String checkName) {
        HashMap< String, Object> map=new HashMap<String, Object>();
        boolean bSaveOk = false;
        boolean bCheckOk = false;
        try{
            // 如果校验通过，入库eshop_xbcheck
            if ("0".equals(checkCode)) {
                StringBuffer sqlStr=new StringBuffer();
                sqlStr.append("insert into eshop_xbcheck (id,external_order_id,product_name,link_phone,receiver,address,");
                if(smWhiteOrder.getSendTime()!=null){
                    sqlStr.append("send_time,");
                }
                sqlStr.append("name,idcard_code,remark,create_time,channel_id,channel_name,provincename,cityname,countyname,flag) ");
                sqlStr.append("values (");
                sqlStr.append("'"+smWhiteOrder.getId()+"',");
                sqlStr.append("'"+smWhiteOrder.getExternalOrderId()+"',");
                sqlStr.append("'"+smWhiteOrder.getProductName()+"',");
                sqlStr.append("'"+smWhiteOrder.getLinkPhone()+"',");
                sqlStr.append("'"+smWhiteOrder.getReceiver()+"',");
                sqlStr.append("'"+smWhiteOrder.getAddress()+"',");
                if(smWhiteOrder.getSendTime()!=null){
                    sqlStr.append("str_to_date('"+smWhiteOrder.getSendTimeStr()+"', '%Y-%m-%d %H:%i:%s')"+",");
                }
                sqlStr.append("'"+smWhiteOrder.getName()+"',");
                sqlStr.append("'"+smWhiteOrder.getIdcardCode()+"',");
                sqlStr.append("'"+smWhiteOrder.getRemark()+"',");
                sqlStr.append("now(),");
                sqlStr.append("'"+smWhiteOrder.getChannelId()+"',");
                sqlStr.append("'"+smWhiteOrder.getChannelName()+"',");
                sqlStr.append("'"+smWhiteOrder.getProvinceName()+"',");
                sqlStr.append("'"+smWhiteOrder.getCityName()+"',");
                sqlStr.append("'"+smWhiteOrder.getCountyName()+"',");
                sqlStr.append("'2'");//流转导入标识
                sqlStr.append(")");
                System.out.println("import smallWhiteCardOrder with excel sql==" + sqlStr.toString());
                SqlInsert.insert(sqlStr.toString());
                bSaveOk = true;
                bCheckOk = true;
            } else {  //校验不通过，入库eshop_xbcheck_fail
                StringBuffer sqlStr=new StringBuffer();
                sqlStr.append("insert into eshop_xbcheck_fail (id,external_order_id,product_name,link_phone,receiver,address,");
                if(smWhiteOrder.getSendTime()!=null){
                    sqlStr.append("send_time,");
                }
                sqlStr.append("name,idcard_code,remark,create_time,channel_id,channel_name,provincename,cityname,countyname,CHERK_CODE,check_name,flag) ");
                sqlStr.append("values (");
                sqlStr.append("'"+smWhiteOrder.getId()+"',");
                sqlStr.append("'"+smWhiteOrder.getExternalOrderId()+"',");
                sqlStr.append("'"+smWhiteOrder.getProductName()+"',");
                sqlStr.append("'"+smWhiteOrder.getLinkPhone()+"',");
                sqlStr.append("'"+smWhiteOrder.getReceiver()+"',");
                sqlStr.append("'"+smWhiteOrder.getAddress()+"',");
                if(smWhiteOrder.getSendTime()!=null){
                    sqlStr.append("str_to_date('"+smWhiteOrder.getSendTimeStr()+"', '%Y-%m-%d %H:%i:%s')"+",");
                }
                sqlStr.append("'"+smWhiteOrder.getName()+"',");
                sqlStr.append("'"+smWhiteOrder.getIdcardCode()+"',");
                sqlStr.append("'"+smWhiteOrder.getRemark()+"',");
                sqlStr.append("now(),");
                sqlStr.append("'"+smWhiteOrder.getChannelId()+"',");
                sqlStr.append("'"+smWhiteOrder.getChannelName()+"',");
                sqlStr.append("'"+smWhiteOrder.getProvinceName()+"',");
                sqlStr.append("'"+smWhiteOrder.getCityName()+"',");
                sqlStr.append("'"+smWhiteOrder.getCountyName()+"',");
                sqlStr.append("'"+checkCode+"',");
                sqlStr.append("'"+checkName+"',");
                sqlStr.append("'2'");//流转导入标识
                sqlStr.append(")");
                System.out.println("import smallWhiteCardOrder with excel sql==" + sqlStr.toString());
                SqlInsert.insert(sqlStr.toString());
                bSaveOk = true;
            }

        }catch(Exception e){
            //msg="订单导入异常，请联系管理员";
            System.out.println(smWhiteOrder.getLinkPhone()+"import smallWhiteCardOrder with excel 异常==" + e.getMessage());
            e.printStackTrace();
        }
        map.put("bSaveOk", bSaveOk);
        map.put("bCheckOk", bCheckOk);
//		map.put("failedMsg", failedMsg);
        return map;

    }
    */
/**
     * 校验日期格式
     * @param str
     * @return boolean
     *//*

    private static boolean isValidDate(String str) {
        // 指定日期格式为四位年/两位月份/两位日期，注意yyyy/MM/dd区分大小写；
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {

            Date date = (Date) formatter.parse(str);
            return str.equals(formatter.format(date));
        } catch (Exception  e) {
            // 如果throw java.text.ParseException或者NullPointerException，就说明格式不对
            return false;
        }
    }
    */
/**
     * 校验收获电话号码合法性
     * @param linkPhone
     * @return
     *//*

    public boolean checkLinkPhone (String linkPhone) {
        String regex = "^((13[0-9])|(14[0-9])|(15([0-9]))|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";
        if(StringUtils.isBlank(linkPhone)){
            return false;
        }
        if (linkPhone.length()!=11) {
            return false;
        }else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(linkPhone);
            boolean isMatch = m.matches();
            return isMatch;
        }
    }

    */
/**
     * 小白订单拦截校验
     * @param linkPhone,address,idcardCode
     * @return
     *//*

    public Map<String, Object> smallWhiteCheck(Integer irow,String channelId,String linkPhone,String address,String idcardCode,String name) {
        System.out.println("---------校验开始");
        Map<String,Object> map=new HashMap<String, Object>();
        try{
            //收货电话-电渠本地库黑名单2.4
            String blackPhoneSql = "select count(*) from eshop_receiver_blacklist t where t.black_type = 2 and t.black_value = '"+linkPhone+"'";
            List<String[]> blackPhoneList = SqlQuery.findList(blackPhoneSql);
            if(null != blackPhoneList && blackPhoneList.size() > 0){
                int count = Integer.valueOf(blackPhoneList.get(0)[0]);
                if(count > 0){
                    map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                    map.put("checkCode", "2.4");
                    map.put("checkName","收货电话-电渠本地库黑名单");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--联系电话在黑名单中，无法进行导入");
                    return map;
                }
            }
            System.out.println("2.4");

            //收货电话-90天1单 2.5
            //小白卡表内校验
//			String qrySwSql="select count(link_Phone) from eshop_xbcheck t where t.link_phone='"+linkPhone+"' and (t.send_time > sysdate-90 or t.create_time > sysdate-90)";
            String qrySwSql="select count(link_Phone) from eshop_xbcheck t where t.link_phone='"+linkPhone+"' and (t.send_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  or t.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY) )";
            List<String[]> swlist = SqlQuery.findList(qrySwSql);
            if(null != swlist && swlist.size() > 0){
                int count = Integer.valueOf(swlist.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                    map.put("checkCode", "2.5");
                    map.put("checkName","收货电话-90天1单");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--90天内已有订单，无法进行导入，请确认---在小白卡表中");
                    return map;
                }
            }
            //流转订单表中校验
            String qryOrderSql="select count(distinct eo.order_id) from marketuser.eshop_order eo " +
                    "left join eshop_network_info en on en.order_id = eo.order_id " +
                    "where eo.link_phone = '"+linkPhone+"' and eo.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY) " +
                    "and eo.status <> '4' and eo.status <> '6'";
            List<String[]> orderlist = SqlQuery.findList(qryOrderSql);
            if(null != orderlist && orderlist.size() > 0){
                int count = Integer.valueOf(orderlist.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                    map.put("checkCode", "2.5");
                    map.put("checkName","收货电话-90天1单");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--90天内已有订单，无法进行导入，请确认---在流转订单表中");
                    return map;
                }
            }
            System.out.println("2.5");
            //如果地址不为空，进行校验
            if(StringUtils.isNotBlank(address)){
                //校验代理商、地址白名单
                String whiteChannelIdSql = "select count(*) from eshop_receiver_blacklist t where t.black_type = 11 and t.black_value = '"+channelId+"'";
                List<String[]> whiteChannelIdList = SqlQuery.findList(whiteChannelIdSql);
                if(null != whiteChannelIdList && whiteChannelIdList.size() > 0){
                    int count = Integer.valueOf(whiteChannelIdList.get(0)[0]);
                    if(count > 0){
                        String blackAdressSql = "select t.black_value from eshop_receiver_blacklist t where t.black_type = 12 ";
                        List<String[]> addressList = SqlQuery.findList(blackAdressSql);
                        if(null != addressList && addressList.size() > 0){
                            for(String[] temp : addressList){
                                String addressBlack = temp[0];
                                if(address.indexOf(addressBlack) > -1){
                                    map.put("checkCode", "0");
                                    map.put("checkName","省安防拦截校验通过");
                                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，渠道和收货地址在白名单中");
                                    return map;
                                }
                            }
                        }
                    }
                }

                //收货地址-电渠本地库黑名单 2.6
                String blackAdressSql = "select t.black_value from eshop_receiver_blacklist t where t.black_type = 3 ";
                List<String[]> addressList = SqlQuery.findList(blackAdressSql);
                if(null != addressList && addressList.size() > 0){
                    for(String[] temp : addressList){
                        String addressBlack = temp[0];
                        if(address.indexOf(addressBlack) > -1){
                            map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                            map.put("checkCode", "2.6");
                            map.put("checkName","收货地址-电渠本地库黑名单");
                            System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址在黑名单中");
                            return map;
                        }
                    }
                }
                System.out.println("2.6");

                //收货地址-90天1单 2.7
                //小白卡表中
//				String qryAdressSwSql="select count(address) from eshop_xbcheck t where t.address='"+address+"' and (t.send_time > sysdate-90 or t.create_time > sysdate-90)";
                String qryAdressSwSql="select count(address) from eshop_xbcheck t where t.address='"+address+"' and (t.send_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  or t.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY) )";
                List<String[]> swAdresslist = SqlQuery.findList(qryAdressSwSql);
                if(null != swAdresslist && swAdresslist.size() > 0){
                    int count = Integer.valueOf(swAdresslist.get(0)[0]);
                    if(count>0){
                        map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                        map.put("checkCode", "2.7");
                        map.put("checkName","收货地址-90天1单");
                        System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址90天内已有订单，无法进行导入，请确认---在小白卡表中");
                        return map;
                    }
                }
                //流转订单表中
                String qryAdressOrderSql = "select count(distinct eo.order_id) from marketuser.eshop_order eo " +
                        "left join eshop_network_info en on en.order_id = eo.order_id " +
                        "where eo.address = '" + address + "' and eo.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  " +
                        "and eo.status <> '4' and eo.status <> '6'";
                List<String[]> adressList = SqlQuery.findList(qryAdressOrderSql);
                if(null != adressList && adressList.size() > 0){
                    int count = Integer.valueOf(adressList.get(0)[0]);
                    if(count>0){
                        map.put("msg", "第"+irow+"行，省安防拦截；</br>");
                        map.put("checkCode", "2.7");
                        map.put("checkName","收货地址-90天1单");
                        System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址在90天内已有订单，无法进行导入，请确认---在流转订单表中");
                        return map;
                    }
                }
            }
            System.out.println("2.7");
//			map.put("msg", "正常通过校验，不拦截订单");
            map.put("checkCode", "0");
        }catch(Exception e){
            map.put("msg", "数据校验异常,请联系管理员。");
            map.put("checkCode", "4");
            map.put("checkName", "数据校验异常");
            e.printStackTrace();
            System.out.println("import smallWhiteCardOrder with excel===导入异常"+e.getMessage());
        } catch (Throwable e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return map;
    }
    */
/**
     * 校验小白卡数据表和流转订单表中联系电话90天内是否已有订单、校验联系电话黑名单
     * @param linkPhone
     * @return
     *//*

    public Map<String, Object> checkIn90Order(Integer irow,String linkPhone) {
        Map<String,Object> map=new HashMap<String, Object>();
        try{
            if(StringUtils.isBlank(linkPhone)){
                map.put("msg", "第"+irow+"行，省安防拦截；");
                map.put("code", "1");
                System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货电话为空");
                return map;
            }
//			String qrySwSql="select count(link_Phone) from eshop_xbcheck t where t.link_phone='"+linkPhone+"' and (t.send_time > sysdate-90 or t.create_time > sysdate-90)";
            String qrySwSql="select count(link_Phone) from eshop_xbcheck t where t.link_phone='"+linkPhone+"' and (t.send_time >DATE_ADD(NOW(),INTERVAL -90 DAY)  or t.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY) )";
            List<String[]> swlist = SqlQuery.findList(qrySwSql);
            if(null != swlist && swlist.size() > 0){
                int count = Integer.valueOf(swlist.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；");
                    map.put("code", "2");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--90天内已有订单，无法进行导入，请确认---在小白卡表中");
                    return map;
                }
            }
            String qryOrderSql="select count(distinct eo.order_id) from marketuser.eshop_order eo " +
                    "left join eshop_network_info en on en.order_id = eo.order_id " +
                    "where eo.link_phone = '"+linkPhone+"' and eo.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  " +
                    "and eo.status <> '4' and eo.status <> '6'";
            List<String[]> orderlist = SqlQuery.findList(qryOrderSql);
            if(null != orderlist && orderlist.size() > 0){
                int count = Integer.valueOf(orderlist.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；");
                    map.put("code", "2");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--90天内已有订单，无法进行导入，请确认---在流转订单表中");
                    return map;
                }
            }
            String blackSql = "select count(*) from eshop_receiver_blacklist t where t.black_type = 2 and t.black_value = '"+linkPhone+"'";
            List<String[]> list2 = SqlQuery.findList(blackSql);
            if(null != list2 && list2.size() > 0){
                int count = Integer.valueOf(list2.get(0)[0]);
                if(count > 0){
                    map.put("msg", "第"+irow+"行，省安防拦截；");
                    map.put("code", "3");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，"+linkPhone+"--90天内已有订单，无法进行导入，请确认---在流转订单表中");
                    return map;
                }
            }
            map.put("msg", "成功");
            map.put("code", "0");
        }catch(Exception e){
            map.put("msg", "数据校验异常");
            map.put("code", "4");
            e.printStackTrace();
            System.out.println("import smallWhiteCardOrder with excel===导入异常"+e.getMessage());
        }
        return map;
    }

    */
/**
     * 校验小白卡数据表和流转订单表中收货地址90天内是否已有订单、校验收货地址黑名单
     * @param
     * @return
     *//*

    public Map<String, Object> checkAddrOrder(Integer irow,String address) {
        Map<String,Object> map=new HashMap<String, Object>();
        try{
            if(StringUtils.isBlank(address)){
                map.put("msg", "第"+irow+"行，收货地址为空；");
                map.put("code", "1");
                System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址为空");
                return map;
            }
//			String qrySwSql="select count(address) from eshop_xbcheck t where t.address='"+address+"' and (t.send_time > sysdate-90 or t.create_time > sysdate-90)";
            String qrySwSql="select count(address) from eshop_xbcheck t where t.address='"+address+"' and (t.send_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  or t.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY) )";
            List<String[]> swlist = SqlQuery.findList(qrySwSql);
            if(null != swlist && swlist.size() > 0){
                int count = Integer.valueOf(swlist.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；");
                    map.put("code", "2");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址90天内已有订单，无法进行导入，请确认---在小白卡表中");
                    return map;
                }
            }
            String qryOrderSql = "select count(distinct eo.order_id) from marketuser.eshop_order eo " +
                    "left join eshop_network_info en on en.order_id = eo.order_id " +
                    "where eo.address = '" + address + "' and eo.create_time > DATE_ADD(NOW(),INTERVAL -90 DAY)  " +
                    "and eo.status <> '4' and eo.status <> '6'";
            List<String[]> list21 = SqlQuery.findList(qryOrderSql);
            if(null != list21 && list21.size() > 0){
                int count = Integer.valueOf(list21.get(0)[0]);
                if(count>0){
                    map.put("msg", "第"+irow+"行，省安防拦截；");
                    map.put("code", "2");
                    System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址在90天内已有订单，无法进行导入，请确认---在流转订单表中");
                    return map;
                }
            }
            String blackSql = "select t.black_value from eshop_receiver_blacklist t where t.black_type = 3 ";
            List<String[]> addressList = SqlQuery.findList(blackSql);
            if(null != addressList && addressList.size() > 0){
                for(String[] temp : addressList){
                    String addressBlack = temp[0];
                    if(address.indexOf(addressBlack) > -1){
                        map.put("msg", "第"+irow+"行，省安防拦截；");
                        map.put("code", "3");
                        System.out.println("import smallWhiteCardOrder with excel===第"+irow+"行，收货地址在黑名单中");
                        return map;
                    }
                }
            }
            map.put("msg", "成功");
            map.put("code", "0");
        }catch(Exception e){
            map.put("msg", "数据校验异常");
            map.put("code", "4");
            e.printStackTrace();
            System.out.println("import smallWhiteCardOrder with excel===导入异常"+e.getMessage());
        }
        return map;
    }

    public void exportXBSendOrder(){
        HttpServletRequest request = ServletActionContext.getRequest();
        EshopAdmin admin = (EshopAdmin) request.getSession().getAttribute(Cantants.ESHOP_ADMIN_USER);
        Long adminId = admin.getAdminId();
        String adminCompanyIdStr=admin.getCompanyIdStr();
        if(StringUtil.isBlank(adminCompanyIdStr)){
            Log4jUtil.interfaceLogger.info(adminId+"未获取到厂商信息");
            return;
        }
        try {
            HttpServletResponse response = ServletActionContext.getResponse();
            //获取输出流
            OutputStream os = response.getOutputStream();
            String fileName = StringUtil.getNow();
            response.reset();
            response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls");// 设定输出文件头

            response.setContentType("application/msexcel");// 定义输出类型
            WritableWorkbook wbook = Workbook.createWorkbook(os);// 创建Excel表
            WritableSheet wsheet = wbook.createSheet("小白发货订单导出", 0); // sheet名称
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 10,
                    WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
                    Colour.BLACK);
            // 单元格格式
            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC = new WritableCellFormat(wfont);
            // 设置背景颜色
            wcfFC.setBackground(Colour.YELLOW2);
            // 把水平对齐方式指定为居中
            wcfFC.setAlignment(Alignment.CENTRE);
            // 把垂直对齐方式指定为居中
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);
            int li = 0;
            */
/*订单号、订单下单时间、订单状态、最后一步处理时间、订单发货或者异常处理的处理人。*//*

            wsheet.addCell(new Label(li++, 0, "订单号 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "代理商名称", wcfFC));
            wsheet.addCell(new Label(li++, 0, "下单时间 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "预设发展人 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "物流商 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "运单号 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "小白卡卡号", wcfFC));
            wsheet.addCell(new Label(li++, 0, "收货人", wcfFC));
            wsheet.addCell(new Label(li++, 0, "联系电话", wcfFC));
            wsheet.addCell(new Label(li++, 0, "地址", wcfFC));
            wsheet.addCell(new Label(li++, 0, "商品名称", wcfFC));
            wsheet.addCell(new Label(li++, 0, "是否可京配", wcfFC));
            wsheet.addCell(new Label(li++, 0, "终端串码", wcfFC));//fixme 小白发货单导出， --导出的excel增加一列：终端串码 by daigp 20200930
            wsheet.addCell(new Label(li++, 0, "订单总金额", wcfFC));//fixme 小白发货单导出， --导出的excel增加一列：订单总金额 by yangyq 20201022
            wsheet.addCell(new Label(li++, 0, "终端信息", wcfFC));


            wsheet.setColumnView(0, 30);
            wsheet.setColumnView(1, 30);
            wsheet.setColumnView(2, 30);
            wsheet.setColumnView(3, 30);
            wsheet.setColumnView(4, 30);
            wsheet.setColumnView(5, 30);
            wsheet.setColumnView(6, 30);

            // 设置表内循环样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont);
            wfont = new WritableFont(WritableFont.ARIAL, 11,
                    WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
                    Colour.BLACK);
            wcfFC2 = new WritableCellFormat(wfont);
            wcfFC2.setWrap(true);

            List<Map<String, String>> xbOrderList = smallWhiteOrderService.qryXBSendOrder(adminCompanyIdStr);
//			List<Map<String, String>> xbOrderList = smallWhiteOrderService.qryXBSendOrder();

            int row = 1;
            for (Map<String, String> map : xbOrderList) {
                String orderId = String.valueOf(map.get("orderId"));
                String channelName = String.valueOf(map.get("channelName"));
                String createTime = String.valueOf(map.get("createTime"));
                String receiver = String.valueOf(map.get("receiver"));
                String linkPhone = String.valueOf(map.get("linkPhone"));
                String address = String.valueOf(map.get("address"));
                String productName = String.valueOf(map.get("productName"));
                String ifJdSend = String.valueOf(map.get("ifJdSend"));
                String totalPrice = String.valueOf(map.get("totalPrice"));
                String terminalInfo = String.valueOf(map.get("terminalInfo"));

                int lj = 0;
                wsheet.addCell(new Label(lj++, row, orderId==null?"":orderId , wcfFC2));
                wsheet.addCell(new Label(lj++, row, channelName==null?"":channelName , wcfFC2));
                wsheet.addCell(new Label(lj++, row, createTime==null?"":createTime , wcfFC2));
                wsheet.addCell(new Label(lj++, row, "", wcfFC2));
                wsheet.addCell(new Label(lj++, row, "", wcfFC2));
                wsheet.addCell(new Label(lj++, row, "", wcfFC2));
                wsheet.addCell(new Label(lj++, row, "", wcfFC2));
                wsheet.addCell(new Label(lj++, row, receiver==null?"":receiver , wcfFC2));
                wsheet.addCell(new Label(lj++, row, linkPhone==null?"":linkPhone , wcfFC2));
                wsheet.addCell(new Label(lj++, row, address==null?"":address , wcfFC2));
                wsheet.addCell(new Label(lj++, row, productName==null?"":productName , wcfFC2));
                wsheet.addCell(new Label(lj++, row, ifJdSend==null?"":ifJdSend , wcfFC2));
                wsheet.addCell(new Label(lj++, row, "" , wcfFC2));//fixme 小白发货单导出， --导出的excel增加一列：终端串码 by daigp 20200930
                wsheet.addCell(new Label(lj++, row, totalPrice==null?"":fenToYuan(totalPrice) , wcfFC2));//fixme 小白发货单导出， --导出的excel增加一列：订单总金额 by yangyq 20201022
                wsheet.addCell(new Label(lj++, row, StringUtil.isNullOrEmpty(terminalInfo)?"":terminalInfo , wcfFC2));


                row++;
            }
            wbook.write();//写入文件
            if(wbook != null){
                wbook.close();
            }
            if(os != null){
                os.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String importXBSendOrder(){

        msg="";

        eshopAdmin = Cantants.getEshopAdmin();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("import importXBSendOrder with excel=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        String fileType = upfileFileName.substring(upfileFileName.lastIndexOf(".")+1,upfileFileName.length());
        System.out.println("import importXBSendOrder with excel==文件名：" + upfileFileName);
        System.out.println("import importXBSendOrder with excel==File：" + upfile);
        if (!fileType.equals("xls")){
            msg="导入失败，文件类型不正确!";
            System.out.println("import importXBSendOrder with excel==" + msg);
            return ERROR;
        }
        try {

            InputStream inputStream = new FileInputStream(upfile);
            Workbook rwb = Workbook.getWorkbook(inputStream);
            Sheet rs = null;
            int countSheets = rwb.getNumberOfSheets();
            if (countSheets < 1){
                rwb.close();
                msg = "该订单文件没有数据";
                System.out.println("import importXBSendOrder with excel==" + msg);
                return ERROR;
            }
            rs = (Sheet)rwb.getSheet(0); // 仅取第一页
            final int rowCount = rs.getRows(); //行数
            int colCount = rs.getColumns(); //列数
            if(rowCount<2){
                msg = "文件中没有订单记录，请确认";
                System.out.println("import importXBSendOrder with excel==" + msg);
                return ERROR;
            }
            //fixme 活动期间，需要支持日订单4万量的发货处理。单次5000单—— 客户强调必须高效支持4、5小白订单的导出，导入的订单量5000+ by daigp 20200930===开始
            if(rowCount>5000){
                msg = "文件中最多只能有5000行数据，请确认";
                //System.out.println("import importXBSendOrder with excel==" + msg);
                return ERROR;
            }
            //活动期间，需要支持日订单4万量的发货处理。单次5000单—— 客户强调必须高效支持4、5小白订单的导出，导入的订单量5000+ by daigp 20200930===结束

            //fixme 小白订单发货导入，--导出的excel增加一列：终端串码， 内容为上传时用户自己填写到excel中（excel列由 7改为8） by daigp 20200930===开始
            if(colCount<8){
                msg = "文件模板不正确，请确认";
                System.out.println("import importXBSendOrder with excel==" + msg);
                return ERROR;
            }
            //小白订单发货导入，--导出的excel增加一列：终端串码， 内容为上传时用户自己填写到excel中 by daigp 20200930===结束

            //校验循环
            Map<Object, Object> params = new LinkedHashMap<Object, Object>();
            params.put("businessType", 2);//读取代理商列表
            final List<EshopAgentsInfo> agentsInfoList = eshopAgentsInfoService.getAllRecords(params);
            List<String> agentsNameList = new ArrayList<String>();
            for(EshopAgentsInfo agentsInfo : agentsInfoList){
                agentsNameList.add(agentsInfo.getAgentsName());
            }
            Map<String, String> distributionIdMap = new HashMap<String, String>();
            Map<String, String> xbCardNumMap = new HashMap<String, String>();
            Map<String, String> orderIdMap = new HashMap<String, String>();

            final List<EshopOrderInfoExcel> orderInfoExcels = new ArrayList<EshopOrderInfoExcel>();
            for (int irow = 1; irow < rowCount; irow++){
                String orderId = ((Sheet) rs).getCell(0, irow).getContents().trim();//订单号
                String channelName = ((Sheet) rs).getCell(1, irow).getContents().trim();//代理商名，不校验
                String createTime = ((Sheet) rs).getCell(2, irow).getContents().trim();//下单时间，不校验
                String preStaff = ((Sheet) rs).getCell(3, irow).getContents().trim();//预设发展人，不校验
                String logisticsAgentsName = ((Sheet) rs).getCell(4, irow).getContents().trim();//物流商名称，校验空和是否存在
                String distributionId = ((Sheet) rs).getCell(5, irow).getContents().trim();//运单号，校验空和重复性
                String xbCardNum = ((Sheet) rs).getCell(6, irow).getContents().trim();//小白卡卡号，校验空
                String terminalCode = ((Sheet) rs).getCell(12, irow).getContents().trim();//终端串码，不校验 by daigp 20200930

                EshopOrderInfoExcel eshopOrderInfoExcel = new EshopOrderInfoExcel();
                eshopOrderInfoExcel.setOrderId(orderId);
                eshopOrderInfoExcel.setChannelName(channelName);
                eshopOrderInfoExcel.setCreateTime(createTime);
                eshopOrderInfoExcel.setPreStaff(preStaff);
                eshopOrderInfoExcel.setLogisticsAgentsName(logisticsAgentsName);
                eshopOrderInfoExcel.setDistributionId(distributionId);
                eshopOrderInfoExcel.setXbCardNum(xbCardNum);
                eshopOrderInfoExcel.setTerminalCode(terminalCode);//终端串码，不校验 by daigp 20200930
                orderInfoExcels.add(eshopOrderInfoExcel);

                if(StringUtil.isNullOrEmpty(logisticsAgentsName)){
                    msg+="第"+irow+"行，物流商名称为空；";
                }

                // 订单号是否重复
                boolean isOrderId = orderIdMap.containsKey(orderId);
                if (isOrderId) {
                    msg += "第" + irow + "行，订单号【" + orderId + "】重复；";
                } else {
                    orderIdMap.put(orderId, orderId);
                }
                // 校验运单号是否重复
                boolean isHadDis = distributionIdMap.containsKey(distributionId);
                if (isHadDis) {
                    msg += "第" + irow + "行，运单号【" + distributionId + "】重复；";
                } else {
                    distributionIdMap.put(distributionId, distributionId);
                }
                // 小白卡卡号是否重复
                boolean isHadCard = xbCardNumMap.containsKey(xbCardNum);
                if (isHadCard) {
                    msg += "第" + irow + "行，小白卡卡号【" + xbCardNum + "】重复；";
                } else {
                    xbCardNumMap.put(xbCardNum, xbCardNum);
                }

                boolean agentsFlag = false;
                if(agentsInfoList!=null&&agentsInfoList.size()>0){
                    for(EshopAgentsInfo agentsInfo : agentsInfoList){
                        if(logisticsAgentsName.equals(agentsInfo.getAgentsName())){
                            agentsFlag = true;
                        }
                    }
                }
                if(!agentsFlag){
                    msg+="第"+irow+"行，物流商名称不是系统中配置的物流商；";
//            		System.out.println("import importXBSendOrder with excel"+msg);
                }

                if(StringUtil.isNullOrEmpty(distributionId)){
                    msg+="第"+irow+"行，运单号为空；";
//            		System.out.println("import importXBSendOrder with excel"+msg);
                }
                String jbmpQuerySql = "select id,order_id,next_task_code from eshop_jbmp4_log where order_id='" + orderId + "' and next_task_code='" + JbpmType.JbpmOrder_Accept + "' ";
                List jbmpList = SqlQuery.findList(jbmpQuerySql);
                if (jbmpList != null && jbmpList.size() > 0) {
                    msg += "第" + irow + "行，订单【" + orderId + "】已完成发货；";
                } else {
                    String sql = "select distribution_id,order_id from eshop_distribution where distribution_id = '" + distributionId + "'";
                    List<String[]> list = SqlQuery.findList(sql);

                    if (list != null && list.size() > 0) {
                        String orderIdDb = list.get(0)[1];
                        if (!orderIdDb.equals(orderId)) {
                            msg += "第" + irow + "行，运单号已存在于数据库中；";
//            				System.out.println("import importXBSendOrder with excel"+msg);
                        } else {

                            String deleteItem = "DELETE FROM ESHOP_DISTRIBUTION_ITEM WHERE DISTRIBUTION_ID = '" + distributionId + "'";
                            SqlDelete.delete(deleteItem);
                            String deleteSql = "DELETE FROM ESHOP_DISTRIBUTION WHERE DISTRIBUTION_ID = '"+distributionId+"'";
                            SqlDelete.delete(deleteSql);

                        }
                    }
                }

                if(StringUtil.isNullOrEmpty(xbCardNum)){
                    msg+="第"+irow+"行，小白卡卡号为空；";
//            		System.out.println("import importXBSendOrder with excel"+msg);
                }
                try{
                    Long.parseLong(xbCardNum);
                }catch(Exception e){
                    msg+="第"+irow+"行，小白卡卡号格式异常；";
                    return ERROR;
                }
                //订单发货的时候白卡出库by daigp 20200928====开始
                Log4jUtil.systemLog("queryEshopCardInfoByCardId开始：xbCardNum"+xbCardNum);
                List<EshopCardInfo> eshopCardInfoList = uimInfoService.queryEshopCardInfoByCardId(xbCardNum);
                Log4jUtil.systemLog("queryEshopCardInfoByCardId开始：eshopCardInfoList"+eshopCardInfoList.size());
                if(eshopCardInfoList.size()==0){
                    msg+="第"+irow+"行,卡号【"+xbCardNum+"】不可用；";
                }
                //订单发货的时候白卡出库by daigp 20200928====结束

            }
            System.out.println("import importXBSendOrder with excel "+DateUtil.currentTime()+ "=="+msg);
            if(!StringUtil.isNullOrEmpty(msg)){
                return ERROR;
            }
            final Long adminId = eshopAdmin.getAdminId();
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Log4jUtil.importExcelLogger.info("【导入开始】--文件名称【" + upfileFileName + "】--上传账户【" + eshopAdmin.getUserName() + "】--开始时间【"+DateUtil.currentTime()+"】--总行数【"+(rowCount - 1)+"】");
                    Long startTime = System.currentTimeMillis();
                    int errorCount = 0;
                    for (EshopOrderInfoExcel orderInfoExcel : orderInfoExcels) {
                        String orderId = orderInfoExcel.getOrderId();//订单号
                        String logisticsAgentsName = orderInfoExcel.getLogisticsAgentsName();//物流商名称，校验空和是否存在
                        String distributionId = orderInfoExcel.getDistributionId();//运单号，校验空和重复性
                        String xbCardNum = orderInfoExcel.getXbCardNum();//小白卡卡号，校验空
                        xbCardNum = xbCardNum.replace("-", "");
                        String logisticsAgentsId = "";
                        //fixme 订单发货的时候终端串码有值存表by daigp 20200930===开始
                        String terminalCode=orderInfoExcel.getTerminalCode();
                        //订单发货的时候终端串码有值存表by daigp 20200930===结束
                        try {
                            if (agentsInfoList != null && agentsInfoList.size() > 0) {
                                for (EshopAgentsInfo agentsInfo : agentsInfoList) {
                                    if (logisticsAgentsName.equals(agentsInfo.getAgentsName())) {
                                        logisticsAgentsId = String.valueOf(agentsInfo.getAgentsId());
                                    }
                                }
                            }

                            EshopOrder eo = eshopOrderService.find(Long.parseLong(orderId));

                            String orderRecipientId = getSeqStr("", null, 6);
                            Date date = new Date();

                            EshopDistribution eshopDistribution = new EshopDistribution();
                            eshopDistribution.setDistributionId(distributionId);
                            eshopDistribution.setEshopOrder(eo);
                            eshopDistribution.setOrderRecipientId(orderRecipientId);
                            // eshopDistribution.setLogisticsId(logisticsId);
                            eshopDistribution.setDistributionStatus("2"); // 2 配送中 3 全票签收  4配送失败
                            eshopDistribution.setUpdateTime(date);
                            eshopDistribution.setAddTime(date);
                            eshopDistribution.setAddUser(adminId);
                            eshopDistribution.setSendConten("小白卡产品");// 配送内容
                            eshopDistribution.setShouldCollection(0L);
                            eshopDistribution.setLogisticsAgentsId(logisticsAgentsId); // 配送物流商
                            eshopDistribution.setPayChannelId(eo.getEshopPayChannel().getPayChannelId());
                            eshopDistribution.setInterdesc("success");
                            eshopDistributionService.addNew(eshopDistribution);

                            List<EshopOrderItem> itemList = eshopOrderService.listOrderItems(eo);
                            for (EshopOrderItem eshopOrderItem : itemList) {
                                EshopDistributionItem distributionItem = new EshopDistributionItem();
                                distributionItem.setDistribution(eshopDistribution);
                                distributionItem.setEshopOrderItem(eshopOrderItem);
                                eshopDistributionItemService.addNew(distributionItem);
                                //fixme 订单发货的时候终端串码有值存表by daigp@20200930===开始
                                Long productId=eshopOrderItem.getProductId();
                                Long orderItemId=eshopOrderItem.getOrderItemId();
                                System.out.println("orderId:==========="+orderId);
                                System.out.println("orderItemId:==========="+orderItemId);

                                Map<Object, Object> map = new HashMap<Object, Object>();
                                map.put("orderId", orderId);
                                map.put("orderItemId", orderItemId);
                                //附属信息表中业务发展人和小白卡号（iccid）
                                List<EshopOrderAuxiliaryInfo> auxiliaryInfoList = eshopOrderAuxiliaryInfoService.getAllRecords(map);
                                if(productId==0L){
                                    if (auxiliaryInfoList != null && auxiliaryInfoList.size() > 0) {
                                        for (EshopOrderAuxiliaryInfo eshopOrderAuxiliaryInfo : auxiliaryInfoList) {
                                            //eshop_order_item.product_id = 0 表示 白卡的订单项
                                            eshopOrderAuxiliaryInfo.setIntelligentCard(xbCardNum);
                                            eshopOrderAuxiliaryInfoService.update(eshopOrderAuxiliaryInfo);
                                        }
                                    }
                                }
                                System.out.println("productId:==========="+productId);
                                System.out.println("terminalCode:==========="+terminalCode);
                                if(productId== 20000L){
                                    if (auxiliaryInfoList != null && auxiliaryInfoList.size() > 0) {
                                        for (EshopOrderAuxiliaryInfo eshopOrderAuxiliaryInfo : auxiliaryInfoList) {
                                            //eshop_order_item.product_id = 20000 表示 终端的订单项
                                            System.out.println("setTerminalCode:==========="+terminalCode);
                                            eshopOrderAuxiliaryInfo.setTerminalCode(terminalCode);
                                            eshopOrderAuxiliaryInfoService.update(eshopOrderAuxiliaryInfo);
                                        }
                                    }
                                }
                                //订单发货的时候终端串码有值存表by daigp@20200930===结束
                            }

                            EshopOrderRecipient eshopOrderRecipient = new EshopOrderRecipient();
                            eshopOrderRecipient.setOrderRecipientId(orderRecipientId);
                            // 如果商品信息为空，则把备注内容作为商品信息（根据订单发起配送）
                            eshopOrderRecipient.setProductinfo("小白商品");

                            eshopOrderRecipient.setDelivery("7"); // 7 送货上门 8 客户自提 (营业厅自取)
                            eshopOrderRecipient.setReceiver(eo.getReceiver());
                            eshopOrderRecipient.setPostCode(eo.getPostCode());
                            eshopOrderRecipient.setAddress(eo.getAddress());
                            eshopOrderRecipient.setLinkPhone(eo.getLinkPhone());

                            // eshopOrderRecipient.setPhone(eshopOrder_logistics.getSmsPhone());
                            eshopOrderRecipient.setPhone("无");

                            eshopOrderRecipient.setIdcardType(eo.getIdcardType());
                            eshopOrderRecipient.setIdcardCode(eo.getIdcardCode());
                            eshopOrderRecipient.setSpecialSay(eo.getSpecialSay());
                            eshopOrderRecipient.setInvoiceHeader(eo.getInvoiceHeader());
                            eshopOrderRecipientService.addNew(eshopOrderRecipient);

                            eo.setToLogisticsInterfaceSt("0");
                            eo.setSendTime(new Date());
                            eshopOrderService.save(eo);

                            //附属信息表中业务发展人和小白卡号（iccid）
//							Map<Object, Object> map = new HashMap<Object, Object>();
//							map.put("orderId", orderId);
//							List<EshopOrderAuxiliaryInfo> auxiliaryInfoList = eshopOrderAuxiliaryInfoService.getAllRecords(map);
//							if (auxiliaryInfoList != null && auxiliaryInfoList.size() > 0) {
//								for (EshopOrderAuxiliaryInfo eshopOrderAuxiliaryInfo : auxiliaryInfoList) {
//									eshopOrderAuxiliaryInfo.setIntelligentCard(xbCardNum);
//									//fixme 订单发货的时候终端串码有值存表by daigp 20200930===开始
//									eshopOrderAuxiliaryInfo.setTerminalCode(terminalCode);
//									//订单发货的时候终端串码有值存表by daigp 20200930===结束
//									eshopOrderAuxiliaryInfoService.update(eshopOrderAuxiliaryInfo);
//								}
//							}

                            //订单发货的时候白卡出库by daigp 20200928====开始
                            EshopCardInfo eshopCardInfo=new EshopCardInfo();
                            eshopCardInfo.setCardId(xbCardNum);
                            eshopCardInfo.setStatus("2");
                            eshopCardInfo.setOutUser(eshopAdmin.getUserName());
                            eshopCardInfo.setOutTime(new Date());
                            System.out.println("updateByPrimaryKeySelective======cardId:"+Long.valueOf(xbCardNum)+"outUser:"+eshopAdmin.getUserName());
                            int num=uimInfoService.updateByPrimaryKeySelective(eshopCardInfo);
                            System.out.println("updateByPrimaryKeySelectiveout======num:"+num);
                            //订单发货的时候白卡出库by daigp 20200928====结束

                            //自动流转发货
                            smallWhiteOrderService.doLogisticsProcess(eo);

                            //代理商订单推送发货状态
                            eshopOrderService.pushDeliveryStatusToAgents(eo);

                            Thread.sleep(1);
                        } catch (Exception e) {
                            e.printStackTrace();
                            String message = "文件名称【" + upfileFileName + "】-上传账户【" + eshopAdmin.getUserName() + "】-订单号【" + orderId + "】-日期【" + DateUtil.currentTime() + "】导入失败！";
                            Log4jUtil.importExcelLogger.info(message);
                            errorCount++;
                        }

                    }
                    Long endTime = System.currentTimeMillis();
                    Log4jUtil.importExcelLogger.info("【导入结束】--文件名称【" + upfileFileName + "】--上传账户【" + eshopAdmin.getUserName() + "】--结束时间【"+DateUtil.currentTime()+"】--成功【"+(rowCount - errorCount - 1)+"】--失败【"+errorCount+"】--总耗时【"+(endTime-startTime)+"毫秒】");
                }
            }).start();
            //保存运单信息

            msg = "导入成功！";


        } catch (Exception e) {
            e.printStackTrace();
            msg = e.getMessage();
            return ERROR;
        }

        return SUCCESS;


    }

    public String batchXBSendOrderPage(){

        return SUCCESS;
    }

    public String batchXBSendOrderInfo1() {
        String sql = "select ed.order_id from eshop_distribution ed where ed.batch_id ="+"1625131061275" + " order by ed.batch_sequence";
        List<String[]> list = SqlQuery.findList(sql);
        System.out.println("=============="+list.size());

        for(int i = 10;i < list.size();i ++){
            String[] a = list.get(i);
            EshopOrder eo = eshopOrderService.getEntityById(a[0]);
            //自动流转发货
            System.out.println(eo.getOrderId()+":工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-start-");
            smallWhiteOrderService.doLogisticsProcess(eo);
            System.out.println("================结束");
            System.out.println(eo.getOrderId()+":工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-end-");

            System.out.println(eo.getOrderId()+":工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-start-");
            eshopOrderService.pushDeliveryStatusToAgents(eo);
            System.out.println(eo.getOrderId()+":工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-end-");

        }

//		String sql = "SELECT eoai.provincename,eoai.cityname,\n" +
//				"\teo.order_id,eoi.order_item_id,eoi.product_name\n" +
//				"    , eo.receiver, eo.link_phone, eo.address,eo.if_send_jd\n" +
//				"  FROM eshop_jbmp4_log ejl, jbpm4_variable jv, jbpm4_task jt, eshop_order eo, eshop_Order_item eoi, eshop_channel_management ec\n" +
//				"  ,eshop_order_auxiliary_info eoai\n" +
//				"  WHERE ejl.order_id = eo.order_id\n" +
//				"    AND eoi.order_id = eo.order_id\n" +
//				"    AND eoai.order_id = eo.order_id\n" +
//				"    AND ec.channel_id = eo.channel_id\n" +
//				"    AND ejl.status = 0\n" +
//				"    AND ejl.id = (\n" +
//				"      SELECT MAX(el.id)\n" +
//				"      FROM eshop_jbmp4_log el\n" +
//				"      WHERE el.order_id = ejl.order_id\n" +
//				"    )\n" +
//				"    AND jv.execution_ = jt.execution_\n" +
//				"    AND jv.key_ = 'order'\n" +
//				"    AND ejl.order_id = to_number(jv.string_value_)\n" +
//				"    AND jt.assignee_ LIKE 'TO_DELIVERY2295%'\n" +
//				"    AND ec.channel_name not LIKE '%测试%'\n" +
//				"    AND eo.channel_id <> '1017'\n" +
//				"    AND eo.post_type = '7'\n" +
//				"    AND eoi.product_id <> '20000'\n" +
//				"    AND eo.company_id IN ('1')";
//		List<String[]> list = SqlQuery.findList(sql);
//		if (null != list && 0 < list.size()) {
//			for(String[] a : list){
//				String provincename = "";
//				String cityname =  "";
//				String orderId =  "";
//				provincename = a[0];
//				cityname = a[1];
//				orderId = a[2];
//				if("".equals(provincename) || "".equals(cityname)){
//					System.out.println("修改订单："+orderId +"为可EMS配送");
//					String updateSql = "update eshop_order eo set eo.if_send_ems = 'N' where eo.order_id = '" + orderId + "'";
//					SqlUpdate.update(updateSql);
//				}else {
//					String updateSql = "update eshop_order eo set eo.if_send_ems = 'Y' where eo.order_id = '" + orderId + "'";
//					SqlUpdate.update(updateSql);
//				}
//			}
//		}

        return SUCCESS;
    }

    */
/**
     * 小白订单批量发货
     * @return
     *//*

    public String batchXBSendOrderInfo() {
        System.out.println("*************小白订单批量发货*************");
        msg = "";
        boolean flag = true;
        long iccid1 = Long.parseLong(ICCIDStart);
        long iccid2 = Long.parseLong(ICCIDEnd);

        List<String> iccidList = uimInfoService.cardCanUseCheck(String.valueOf(iccid1), String.valueOf(iccid2));
        if(null != iccidList && 0 < iccidList.size()){
            msg = "当前存在iccid已出库，请重新校验";
            return ERROR;
        }

        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        if (eshopAdmin == null) {
            msg = "请先进行登录，或确认工号是否正确";
            System.out.println("batchXBSendOrderInfo==" + eshopAdmin + ":" + msg);
            return ERROR;
        }
        String adminCompanyIdStr = eshopAdmin.getCompanyIdStr();
        if (StringUtil.isBlank(adminCompanyIdStr)) {
            Log4jUtil.interfaceLogger.info(adminId + "未获取到厂商信息");
            System.out.println(adminId + "未获取到厂商信息");
            msg = adminId + "未获取到厂商信息";
            return ERROR;
        }

        try {
            //获取当前工号所属渠道
            String adminCompanyId[] = adminCompanyIdStr.split(",");
            List adminCompanyIdList = new ArrayList();
            //在生产环境放开
            if(1 < adminCompanyId.length){
                Log4jUtil.interfaceLogger.info(adminId+"所属渠道为多个,不能进行批量发货,请使用单渠道账号操作");
                System.out.println(adminId+"所属渠道为多个,不能进行批量发货,请使用单渠道账号操作");
                msg=adminId+"所属渠道为多个,不能进行批量发货,请使用单渠道账号操作";
                flag = false;
                return ERROR;
            }
            for (int i = 0; i < adminCompanyId.length; i++) {
                adminCompanyIdList.add(Integer.parseInt(adminCompanyId[i]));
            }

            //手动选择订单集合
            List orderList = new ArrayList();
            if (null != chooseParams && !"".equals(chooseParams)) {
                String orderArr[] = chooseParams.split(",");
                for (int i = 0; i < orderArr.length; i++) {
                    orderList.add(orderArr[i]);
                }
            }

            //配置流转查询条件
            String assignee_ = "";
            if (null != adminCompanyIdStr && !StringUtil.empty(adminCompanyIdStr)) {
                assignee_ = "TO_DELIVERY"+adminId+"%";
            }
            String ifSendJd = "Y";
            if (null != if_send_jd && !StringUtil.empty(if_send_jd)) {
                if("1".equals(if_send_jd)){
                    ifSendJd = "Y";
                }else if("2".equals(if_send_jd)){
                    ifSendJd = "N";
                }
            }
            String ifSendEms = "Y";
            if (null != if_send_ems && !StringUtil.empty(if_send_ems)) {
                if("2".equals(if_send_ems)){
                    ifSendEms = "Y";
                }else if("3".equals(if_send_ems)){
                    ifSendEms = "N";
                }
            }

            Log4jUtil.systemLog("【批量发货开始】--方法名称【batchXBSendOrderInfo】--操作账户【" + eshopAdmin.getUserName() + "】--开始时间【"+DateUtil.currentTime()+"】--发货总数【"+send_num+"】");
            System.out.println("【批量发货开始】--方法名称【batchXBSendOrderInfo】--操作账户【" + eshopAdmin.getUserName() + "】--开始时间【"+DateUtil.currentTime()+"】--发货总数【"+send_num+"】");
            Long startTime = System.currentTimeMillis();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println("批量发货开始-----"+sdf.format(new Date()) +" iccid号段："+iccid1+"-"+iccid2);
            //增加缓存机制防止ng重复请求：先判断是否缓存中是否有值，有就跳出本次逻辑，没有就新增缓存，300s
            String redisKey = logisticsAgentsId + "_" + send_num + "_" + ICCIDStart + "_" + ICCIDEnd;
            System.out.println("批量发货缓存机制redisKey="+ redisKey + "开始");
            String redisVal = String.valueOf(RedisCache.get(redisKey));
            if(StringUtils.isNotBlank(redisVal) && "true".equals(redisVal)){
                System.out.println("批量发货缓存机制redisKey="+ redisKey + "；缓存中数据已存在，跳出本次流程redisVal=" + redisVal);
                msg = "本次批量发货流程未结束，请5分钟之后再试";
                flag = false;
                return ERROR;
            }
            Boolean setCacheResult = RedisCache.setExpier(redisKey, "true", 300);
            System.out.println("批量发货缓存机制redisKey="+ redisKey + "；新增缓存结果setCacheResult=" + setCacheResult);
            try {
                //获取当前岗位下符合条件的小白订单
                if (logisticsAgentsId != null && logisticsAgentsId.length() > 0 && (logisticsAgentsId.equals("17") || logisticsAgentsId.equals("18"))) {
                    if(StringUtil.isNotBlank(product_name)){
                        product_name = URLDecoder.decode(product_name, "UTF-8");
                        System.out.println("product_name:"+product_name);
                    }
                    if(StringUtils.isNotBlank(channel_name)){
                        channel_name = URLDecoder.decode(channel_name, "UTF-8");
                        String channelId = eshopOrderService.selectChannelInfo(channel_name);
                        System.out.println("channel_name:"+channel_name+" channel_id:"+channelId);
                        if(StringUtils.isNotBlank(channelId)){
                            channel_id = channelId;
                            System.out.println("当前指定发货渠道："+channel_id);
                        }
                    }

                    List cannot_send_jd_channel_list = null;
                    if(logisticsAgentsId.equals("17")){
                        cannot_send_jd_channel_list = eshopOrderService.selectCannotSendJdChannel();
                        System.out.println("查询不可京东发货渠道："+cannot_send_jd_channel_list.toString());
                        if(StringUtils.isNotBlank(channel_id) && cannot_send_jd_channel_list.contains(channel_id)){
                            msg = "当前渠道：" + channel_name + " 不可使用京东发货，请选择其它物流！";
                            flag = false;
                            return ERROR;
                        }
                    }
                    xbOrderToDeliveryList = eshopOrderService.findXBOrderToDelivery(adminCompanyIdList, orderList, Integer.parseInt(send_num), assignee_, ifSendJd,product_name,channel_id,cannot_send_jd_channel_list,pubCode);
                    System.out.println("获取当前岗位下符合条件的小白订单(可京配小白订单):"+xbOrderToDeliveryList.size()+"单");

                    if (null != xbOrderToDeliveryList && 0 < xbOrderToDeliveryList.size()) {
                        if (xbOrderToDeliveryList.size() < Integer.parseInt(send_num)) {
                            msg = "当前符合条件的订单不足" + send_num + "单,当前可京东发货单量:" + xbOrderToDeliveryList.size();
                            flag = false;
                            return ERROR;
                        } else {
                            //订单匹配ICCID 、 调用京东物流下单接口
                            long l = iccid2 - iccid1 + 1;
                            if (xbOrderToDeliveryList.size()==l) {
                                long bg = System.currentTimeMillis();
                                System.out.println("循环创建物流开始-------"+bg);
                                System.out.println("创建物流订单集合-------"+xbOrderToDeliveryList.toString());
                                List<Map<String, Object>> deliveryMapTemp=new ArrayList<Map<String, Object>>();

                                //定义线程池异步执行
                                ExecutorService pool = new ThreadPoolExecutor(
                                        20,
                                        150,
                                        60L,
                                        TimeUnit.SECONDS,
                                        new LinkedBlockingQueue<>(2000),
                                        Executors.defaultThreadFactory(),
                                        new ThreadPoolExecutor.AbortPolicy());
                                final CountDownLatch countDownLatch = new CountDownLatch(xbOrderToDeliveryList.size());//倒数计数器
                                long start = System.currentTimeMillis();

                                for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {


                                    final int j=i;
                                    pool.execute(new Runnable() {
                                        @Override
                                        public void run() {
                                            try {
                                                Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(j);
                                                String order_id = deliveryMap.get("ORDER_ID").toString();
                                                //匹配ICCID
                                                //deliveryMap.put("iccid", String.valueOf(iccid1 + i));
                                                //创建物流
                                                Set<EshopOrderItem> eshopOrderItems_logistics = new HashSet<EshopOrderItem>();
                                                EshopOrderItem tempItem = eshopOrderItemService.find(Long.parseLong(deliveryMap.get("ORDER_ITEM_ID").toString()));
                                                eshopOrderItems_logistics.add(tempItem);
                                                //调用京东物流接单接口
                                                System.out.println(order_id+":创建物流---------------------开始");
                                                JDLogisticsResp resp = eshopDistributionService.sendOrderToJDNew(eshopOrderItems_logistics, productType,logisticsAgentsId);
                                                System.out.println(order_id+":创建物流---------------------结束:"+resp.toString());
                                                //resultCode 100:创建物流成功 104:重复运单，说明此单可能之前调用过接口，因为某些异常导致未正常入库，运单号可继续使用
                                                if (null != resp && (resp.getResultCode() == 100 || resp.getResultCode() == 104)) {
                                                    if(null != resp.getResultMessage() && !resp.getResultMessage().equals("人工预分拣，请15分钟后重新调用接口") && !resp.getResultMessage().equals("超区")) {
                                                        String distributionId = resp.getDeliveryId();//运单号
                                                        PreSortResult preSortResult = resp.getPreSortResult();//配货信息
                                                        //寄件信息
                                                        deliveryMap.put("senderName", resp.getSender().getName());
                                                        deliveryMap.put("senderPhone", resp.getSender().getPhone());
                                                        deliveryMap.put("senderAddress", resp.getSender().getAddress());
                                                        //配送类型 1特快转递
                                                        deliveryMap.put("productType", productType);
                                                        //运单号
                                                        deliveryMap.put("distributionId", distributionId);
                                                        //马甲单号
                                                        String salesThrOrderId = resp.getSalesThrOrderId();
                                                        deliveryMap.put("salesThrOrderId", salesThrOrderId);

                                                        //京东面单必填信息preSortResult
                                                        deliveryMap.put("siteName", preSortResult.getSiteName());
                                                        deliveryMap.put("road", preSortResult.getRoad());
                                                        deliveryMap.put("sourceSortCenterName", preSortResult.getSourceSortCenterName());
                                                        deliveryMap.put("sourceCrossCode", preSortResult.getSourceCrossCode());
                                                        deliveryMap.put("sourceTabletrolleyCode", preSortResult.getSourceTabletrolleyCode());
                                                        deliveryMap.put("targetSortCenterName", preSortResult.getTargetSortCenterName());
                                                        deliveryMap.put("slideNo", preSortResult.getSlideNo());
                                                        deliveryMap.put("targetTabletrolleyCode", preSortResult.getTargetTabletrolleyCode());
                                                    }else if(resp.getResultMessage().equals("人工预分拣，请15分钟后重新调用接口")){
                                                        deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                        msg += "订单" + order_id + "[京东物流提示：订单正在人工预分拣，建议15分钟后重试，谢谢]&&";
                                                        String updateSql = "update eshop_order eo set eo.if_send_jd = 'N' where eo.order_id = '" + order_id + "'";
                                                        SqlUpdate.update(updateSql);
                                                        //continue;
                                                    }else if(resp.getResultMessage().equals("超区")){
                                                        deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                        msg += "订单" + order_id + "[京东物流提示：超区]&&";
                                                        String updateSql = "update eshop_order eo set eo.if_send_jd = 'N' where eo.order_id = '" + order_id + "'";
                                                        SqlUpdate.update(updateSql);
                                                        //continue;
                                                    }

                                                } else if (null != resp && resp.getResultCode() == 150) {
                                                    deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                    msg += "订单" + order_id + "[京东物流提示：订单正在人工预分拣，建议15分钟后重试，谢谢]&&";
                                                    String updateSql = "update eshop_order eo set eo.if_send_jd = 'N' where eo.order_id = '" + order_id + "'";
                                                    SqlUpdate.update(updateSql);
                                                    //continue;
                                                } else {
                                                    deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                    msg += "订单" + order_id + "[京东物流提示：" + resp.getResultMessage() + "]&&";
                                                    String updateSql = "update eshop_order eo set eo.if_send_jd = 'N' where eo.order_id = '" + order_id + "'";
                                                    SqlUpdate.update(updateSql);
                                                    //continue;
                                                }
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }finally {
                                                countDownLatch.countDown();
                                            }

                                        }
                                    });


                                }

                                countDownLatch.await();
                                pool.shutdown();
                                long end = System.currentTimeMillis();
                                System.out.println(redisKey+"小白京东批量发货 =======END，耗时=" + (end-start));
                                for (int i = 0; i < deliveryMapTemp.size(); i++) {
                                    xbOrderToDeliveryList.remove(deliveryMapTemp.get(i));//移除掉这个订单，防止发货
                                    send_num=String.valueOf(Integer.parseInt(send_num)-1);
                                }
                                long ed = System.currentTimeMillis();
                                System.out.println("循环创建物流结束-------耗时:"+(ed-bg));
                            } else {
                                msg = "订单匹配ICCID异常，请联系管理员";
                                System.out.println(msg);
                                flag = false;
                                return ERROR;
                            }
                        }
                    } else {
                        msg = "系统未查询到符合条件的订单";
                        System.out.println(msg);
                        flag = false;
                        return ERROR;
                    }
                }else if(logisticsAgentsId != null && logisticsAgentsId.length() > 0 && logisticsAgentsId.equals("16")){

                    if(StringUtil.isNotBlank(product_name)){
                        product_name = URLDecoder.decode(product_name, "UTF-8");
                    }
                    if(StringUtils.isNotBlank(channel_name)){
                        channel_name = URLDecoder.decode(channel_name, "UTF-8");
                        String channelId = eshopOrderService.selectChannelInfo(channel_name);
                        if(StringUtils.isNotBlank(channelId)){
                            channel_id = channelId;
                        }
                    }
                    xbOrderToDeliveryList = eshopOrderService.findXBOrderToDeliveryEms(adminCompanyIdList, orderList, Integer.parseInt(send_num), assignee_, ifSendEms,product_name,channel_id);
                    System.out.println("获取当前岗位下符合条件的小白订单(可EMS配送小白订单):"+xbOrderToDeliveryList.size()+"单");
                    if (null != xbOrderToDeliveryList && 0 < xbOrderToDeliveryList.size()) {
                        if (xbOrderToDeliveryList.size() < Integer.parseInt(send_num)) {
                            msg = "当前符合条件的订单不足" + send_num + "单,当前可EMS发货单量:" + xbOrderToDeliveryList.size();
                            flag = false;
                            return ERROR;
                        }else {
                            //订单匹配ICCID 、 调用EMS物流下单接口
                            long l = iccid2 - iccid1 + 1;
                            if (xbOrderToDeliveryList.size() ==l) {
                                long bg = System.currentTimeMillis();
                                System.out.println("循环创建物流开始-------"+bg);
                                System.out.println("创建物流订单集合-------"+xbOrderToDeliveryList.toString());
                                List<Map<String, Object>> deliveryMapTemp=new ArrayList<Map<String, Object>>();

                                final CountDownLatch countDownLatch = new CountDownLatch(xbOrderToDeliveryList.size());//倒数计数器
                                //定义线程池异步执行
                                ExecutorService pool = new ThreadPoolExecutor(
                                        20,
                                        150,
                                        60L,
                                        TimeUnit.SECONDS,
                                        new LinkedBlockingQueue<>(2000),
                                        Executors.defaultThreadFactory(),
                                        new ThreadPoolExecutor.AbortPolicy());

                                long start = System.currentTimeMillis();

                                for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {


                                    final int j=i;
                                    pool.execute(new Runnable() {
                                        @Override
                                        public void run() {
                                            try {
                                                Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(j);
                                                String order_id = deliveryMap.get("ORDER_ID").toString();
                                                //匹配ICCID
                                                //deliveryMap.put("iccid", String.valueOf(iccid1 + i));
                                                //创建物流
                                                Set<EshopOrderItem> eshopOrderItems_logistics = new HashSet<EshopOrderItem>();
                                                EshopOrderItem tempItem = eshopOrderItemService.find(Long.parseLong(deliveryMap.get("ORDER_ITEM_ID").toString()));
                                                eshopOrderItems_logistics.add(tempItem);
                                                //调用EMS物流接单接口
                                                System.out.println(order_id+":创建物流---------------------开始");
                                                OrderPushOut orderPushOut = eshopDistributionService.batchSendOrderToEmsNew(eshopOrderItems_logistics);
                                                System.out.println(order_id+":创建物流---------------------结束");
                                                if (null != orderPushOut && (orderPushOut.getResultCode() == "00")) {
                                                    String distributionId = orderPushOut.getResultMsg();
                                                    String route_code = orderPushOut.getRouteCode();
                                                    //运单号
                                                    deliveryMap.put("distributionId", distributionId);
                                                    //四级分拣码
                                                    deliveryMap.put("route_code", route_code);
                                                    //寄件信息
                                                    deliveryMap.put("senderName", orderPushOut.getSender().getName());
                                                    deliveryMap.put("senderPhone", orderPushOut.getSender().getPhone());
                                                    deliveryMap.put("senderAddress", orderPushOut.getSender().getAddress());

                                                    deliveryMap.put("lsjg", orderPushOut.getSender().getLsjg());
                                                    deliveryMap.put("ysr", orderPushOut.getSender().getYsr());

                                                } else if (null != orderPushOut && orderPushOut.getResultCode() == "-1") {
                                                    deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                    msg += "订单" + order_id + "[调用物流下单接口异常]&&";
                                                } else {
                                                    deliveryMapTemp.add(xbOrderToDeliveryList.get(j));
                                                    msg += "订单" + order_id + "[系统处理异常]&&";
                                                }

                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }finally {
                                                countDownLatch.countDown();
                                            }

                                        }
                                    });
                                }

                                countDownLatch.await();
                                pool.shutdown();

                                long end = System.currentTimeMillis();
                                System.out.println(redisKey+"小白ems批量发货 =======END，耗时=" + (end-start));
                                for (int i = 0; i < deliveryMapTemp.size(); i++) {
                                    xbOrderToDeliveryList.remove(deliveryMapTemp.get(i));//移除掉这个订单，防止发货
                                    send_num=String.valueOf(Integer.parseInt(send_num)-1);
                                }
                                long ed = System.currentTimeMillis();
                                System.out.println("循环创建物流结束-------耗时:"+(ed-bg));
                            } else {
                                msg = "订单匹配ICCID异常，请联系管理员";
                                System.out.println(msg);
                                flag = false;
                                return ERROR;
                            }
                        }

                    }else {
                        msg = "系统未查询到符合条件的订单";
                        System.out.println(msg);
                        flag = false;
                        return ERROR;
                    }

                }

            } catch (Exception e) {
                e.printStackTrace();
                flag = false;
                String message = "方法名称【batchXBSendOrderInfo】-上传账户【" + eshopAdmin.getUserName() + "】-发货数量【\"+send_num+\"】-日期【" + DateUtil.currentTime() + "】批量发货失败！";
                System.out.println("方法名称【batchXBSendOrderInfo】-上传账户【" + eshopAdmin.getUserName() + "】-发货数量【\"+send_num+\"】-日期【" + DateUtil.currentTime() + "】批量发货失败！");
                System.out.println(message+"|"+e.getMessage());
                Log4jUtil.systemLog(message+"|"+e.getMessage());
            } finally {
                if ((!msg.equals("")&&xbOrderToDeliveryList.size() < Integer.parseInt(send_num))||xbOrderToDeliveryList.size()==0) {
                    System.out.println(msg);
                    flag = false;
                    return ERROR;
                }
                //todo daigp@2020823
                //订单匹配ICCID 、 调用EMS物流下单接口
                long l = iccid2 - iccid1 + 1;
                Date date = new Date();
                String currentTimeMillis = String.valueOf(System.currentTimeMillis());
                //上云改造,待等待发送kafka的体外订单id集合
                ArrayList<String> externalOrderList = new ArrayList<>();

                final CountDownLatch countDownLatch = new CountDownLatch(xbOrderToDeliveryList.size());//倒数计数器
                //定义线程池异步执行
                ExecutorService pool = new ThreadPoolExecutor(
                        20,
                        150,
                        60L,
                        TimeUnit.SECONDS,
                        new LinkedBlockingQueue<>(2000),
                        Executors.defaultThreadFactory(),
                        new ThreadPoolExecutor.AbortPolicy());
                long start = System.currentTimeMillis();

                for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {


                    final int j=i;
                    pool.execute(new Runnable() {
                        @Override
                        public void run() {
                            try {

                                Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(j);
                                EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
                                //逻辑修复开始@daigp@20211023
                                List listDitributions = eshopDistributionService.getDitributionByOrderId(Long.valueOf(deliveryMap.get("ORDER_ID").toString()));//查询物流表
                                Long disnum = (Long) listDitributions.get(0);
                                if (disnum > 0) {
                                    Map<String, String> eoa = eshopOrderAuxiliaryInfoService.selectAddressAndIccidByOrderId(deliveryMap.get("ORDER_ID").toString());//获取订单附属表ICCID
                                    if (!StringUtil.isNullOrEmpty(eoa.get("intelligent_card"))) {
                                        HashMap<String, String> params = new HashMap<String, String>();
                                        params.put("cardId", eoa.get("intelligent_card"));
                                        params.put("status", "2");
                                        List<EshopCardInfo> eci = eshopCardInfoMapper.queryEshopCardInfo(params);//判断ICCID出库
                                        if (eci.size() > 0) {
                                            xbOrderToDeliveryList.remove(deliveryMap.get(j));//移除掉这个订单，防止发货
                                            send_num = String.valueOf(Integer.parseInt(send_num) - 1);
                                            //continue;
                                            countDownLatch.countDown();
                                        }
                                    }
                                }
                                //逻辑修复结束@daigp@20211023

//						System.out.println("deliveryMap:"+deliveryMap.toString());
                                //todo daigp@2020823
                                //匹配ICCID
                                deliveryMap.put("iccid", String.valueOf(iccid1 + j));
                                String distributionId = deliveryMap.get("distributionId").toString();
                                String orderRecipientId = getSeqStr("", null, 6);

                                String salesThrOrderId = "";
                                Object sales_Thr_OrderId = deliveryMap.get("salesThrOrderId");
                                if(null != sales_Thr_OrderId){
                                    salesThrOrderId = sales_Thr_OrderId.toString();
                                }
                                eo.setToLogisticsInterfaceSt("0");//推送物流/终端接口状态 0：成功 1：失败
                                eo.setSendTime(new Date());
                                System.out.println("orderId="+eo.getOrderId()+":物流信息更新eshopOrder,externalOrderId=" + eo.getExternalOrderId());
                                eshopOrderService.save(eo);
                                //上云改造，慢sql优化，修改逻辑：流转中满足小白发货条件的订单，发kafka到fortress消费处理业务逻辑 begin 2021年10月13日
                                externalOrderList.add(eo.getExternalOrderId());
                                //上云改造，慢sql优化，修改逻辑：流转中满足小白发货条件的订单，发kafka到fortress消费处理业务逻辑 end

                                //保存物流主表
                                */
/**部分数据用于历史记录查询
                                 * 批次id(batchId)、配送物流商(logisticsAgentsId)、打印时间(addTime)、批次内排序(batchSequence)、快递类型(productType)、内件性质(wayName)、操作用户(addUser)
                                 * 批次备注信息(batchDesc)
                                 *//*

                                EshopDistribution eshopDistribution = new EshopDistribution();
                                if(StringUtil.isNotBlank(salesThrOrderId)){
                                    eshopDistribution.setDistributionId(salesThrOrderId);
                                    eshopDistribution.setDistributionIdMj(distributionId);
                                }else {
                                    eshopDistribution.setDistributionId(distributionId);
                                }

                                eshopDistribution.setProduct_type(productType);//快递类型
                                eshopDistribution.setEshopOrder(eo);
                                eshopDistribution.setOrderRecipientId(orderRecipientId);
                                eshopDistribution.setDistributionStatus("2"); // 2 配送中 3 全票签收  4配送失败
                                eshopDistribution.setUpdateTime(date);
                                eshopDistribution.setAddTime(date);//打印时间
                                eshopDistribution.setAddUser(adminId);//操作用户
                                eshopDistribution.setSendConten("小白卡产品");// 配送内容
                                eshopDistribution.setShouldCollection(0L);
                                eshopDistribution.setLogisticsAgentsId(logisticsAgentsId); // 配送物流商
                                eshopDistribution.setPayChannelId(eo.getEshopPayChannel().getPayChannelId());
                                eshopDistribution.setInterdesc("success");
                                eshopDistribution.setBatchId(currentTimeMillis);//批次id(时间戳)
                                eshopDistribution.setBatchSequence((long) j);//批次内排序
                                eshopDistribution.setWayName(contentsAttribute);//内件性质
                                eshopDistribution.setBatchDesc(JSONObject.fromObject(deliveryMap).toString());
                                System.out.println(eo.getOrderId()+":物流信息更新eshopDistribution:"+eshopDistribution.toString());
                                eshopDistributionService.addNew(eshopDistribution);

//						StringBuffer sql = new StringBuffer("select * from eshop_Distribution where Distribution_id = '");
//						sql.append(distributionId + "'");
//						List<String[]> list = SqlQuery.findList(sql.toString());
//						if(null != list && 0 < list.size()){
//							msg = "表单重复提交!,请到历史发货记录查看发货结果";
//							return ERROR;
//						}else {
//							eshopDistributionService.addNew(eshopDistribution);
//						}

//						更新订单项 订单附属信息表iccid
                                List<EshopOrderItem> itemList = eshopOrderService.listOrderItems(eo);
                                for (EshopOrderItem eshopOrderItem : itemList) {
                                    String distributionItemId = UUID.randomUUID().toString().replace("-", "");
                                    EshopDistributionItem distributionItem = new EshopDistributionItem();
                                    distributionItem.setDistribution(eshopDistribution);
                                    distributionItem.setEshopOrderItem(eshopOrderItem);
                                    distributionItem.setDistributionItemId(distributionItemId);
                                    System.out.println(eo.getOrderId()+":物流信息更新eshopDistributionItem");
                                    eshopDistributionItemService.addNew(distributionItem);

                                    Long productId = eshopOrderItem.getProductId();
                                    Long orderItemId = eshopOrderItem.getOrderItemId();
                                    Map<Object, Object> map = new HashMap<Object, Object>();
                                    map.put("orderId", eo.getOrderId());
                                    map.put("orderItemId", orderItemId);
                                    //附属信息表中业务发展人和小白卡号（iccid）
                                    List<EshopOrderAuxiliaryInfo> auxiliaryInfoList = eshopOrderAuxiliaryInfoService.getAllRecords(map);
                                    if (productId == 0L) {
                                        if (auxiliaryInfoList != null && auxiliaryInfoList.size() > 0) {
                                            for (EshopOrderAuxiliaryInfo eshopOrderAuxiliaryInfo : auxiliaryInfoList) {
                                                //eshop_order_item.product_id = 0 表示 白卡的订单项
                                                eshopOrderAuxiliaryInfo.setIntelligentCard(deliveryMap.get("iccid").toString());
                                                System.out.println(eo.getOrderId()+":物流信息更新eshopOrderAuxiliaryInfo");
                                                eshopOrderAuxiliaryInfoService.update(eshopOrderAuxiliaryInfo);
                                            }
                                        }
                                    }
                                }

                                //更新EshopOrderRecipient
//						EshopOrderRecipient eshopOrderRecipient = new EshopOrderRecipient();
//						eshopOrderRecipient.setOrderRecipientId(orderRecipientId);
//						eshopOrderRecipient.setProductinfo("小白商品");
//						eshopOrderRecipient.setDelivery("7"); // 7 送货上门 8 客户自提 (营业厅自取)
//						eshopOrderRecipient.setReceiver(eo.getReceiver());
//						eshopOrderRecipient.setPostCode(eo.getPostCode());
//						eshopOrderRecipient.setAddress(eo.getAddress());
//						eshopOrderRecipient.setLinkPhone(eo.getLinkPhone());
//						eshopOrderRecipient.setPhone("无");
//						eshopOrderRecipient.setIdcardType(eo.getIdcardType());
//						eshopOrderRecipient.setIdcardCode(eo.getIdcardCode());
//						eshopOrderRecipient.setSpecialSay(eo.getSpecialSay());
//						eshopOrderRecipient.setInvoiceHeader(eo.getInvoiceHeader());
//						System.out.println(eo.getOrderId()+":物流信息更新eshopOrderRecipient");
//						eshopOrderRecipientService.addNew(eshopOrderRecipient);

                                //iccid出库操作
                                EshopCardInfo eshopCardInfo = new EshopCardInfo();
                                eshopCardInfo.setCardId(String.valueOf(iccid1+j));
                                eshopCardInfo.setStatus("2");
                                eshopCardInfo.setOutUser(eshopAdmin.getUserName());
                                eshopCardInfo.setOutTime(new Date());
                                System.out.println("updateByPrimaryKeySelective======cardId:" + Long.valueOf(j) + "outUser:" + eshopAdmin.getUserName());
                                Log4jUtil.systemLog("updateByPrimaryKeySelective======cardId:" + Long.valueOf(j) + "outUser:" + eshopAdmin.getUserName());
                                System.out.println(eo.getOrderId()+":物流信息更新eshopCardInfo");
                                int num=uimInfoService.updateByPrimaryKeySelective(eshopCardInfo);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }finally {
                                countDownLatch.countDown();
                            }

                        }
                    });


                }

                countDownLatch.await();
                pool.shutdown();
                long end = System.currentTimeMillis();
                System.out.println(redisKey+"小白finally批量发货 =======END，耗时=" + (end-start));
                //上云改造，慢sql优化，修改逻辑：流转中满足小白发货条件的订单，发kafka到fortress消费处理业务逻辑 begin 2021年10月13日
                try {
                    //调用接口工程封装好的接口发送kafka消息即可
                    System.out.println("============小白发货调用kakfa本次推送的订单数量为======externalOrderList:" + externalOrderList.size());
                    String kafkaPushUrl  = bundle.getString("kafkaPush");
                    System.out.println(new Date()+"::userName="+eshopAdmin.getUserName()+"::kafkaPushUrl="+kafkaPushUrl);
//					String url = "http://10.62.20.115:17002/ecosp/trade/kfk/xbSendStatusKafkaPush";
                    String response = HttpClientUtil.executePost(kafkaPushUrl, JSONArray.fromObject(externalOrderList).toString());
                    System.out.println("============小白发货调用kakfa本次接口推送响应======response:" + response);
                }catch (Exception e){
                    e.printStackTrace();
                }
                //上云改造，慢sql优化，修改逻辑：流转中满足小白发货条件的订单，发kafka到fortress消费处理业务逻辑 end
                Long endTime = System.currentTimeMillis();
                Log4jUtil.systemLog("【批量发货结束】--方法名称【batchXBSendOrderInfo】--操作账户【" + eshopAdmin.getUserName() + "】--结束时间【"+DateUtil.currentTime()+"】--成功【"+send_num+"】--总耗时【"+(endTime-startTime)+"毫秒】");
                System.out.println("【批量发货结束】--方法名称【batchXBSendOrderInfo】--操作账户【" + eshopAdmin.getUserName() + "】--结束时间【"+DateUtil.currentTime()+"】--成功【"+send_num+"】--总耗时【"+(endTime-startTime)+"毫秒】");
                String message="本批次成功发货"+xbOrderToDeliveryList.size()+"单，失败"+(l-xbOrderToDeliveryList.size())+"单。已使用ICCID卡"+iccid1+"-"+(iccid1+xbOrderToDeliveryList.size()-1)+"";
                msg+=message;//信息补充
                //批量发货完成，移除缓存
                RedisCache.delete(redisKey);
                System.out.println("批量发货缓存机制redisKey="+ redisKey + "批量发货完成，缓存移除完成");
            }


        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
            msg = "系统异常，请联系管理员";
            Log4jUtil.errorLog("时间【"+DateUtil.currentTime()+"】"+"【批量发货异常】--方法名称【batchXBSendOrderInfo】:"+e.getMessage());
            System.out.println("时间【"+DateUtil.currentTime()+"】"+"【批量发货异常】--方法名称【batchXBSendOrderInfo】:"+e.getMessage());
            return ERROR;
        } finally {
            if (flag) {
//				ExecutorService executorService = Executors.newCachedThreadPool();
//				try {
//					for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {
//						final int j = i;
//						executorService.execute(new Runnable() {
//							@Override
//							public void run() {
//								Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(j);
//								EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
//								//自动流转发货
//								System.out.println("工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-start-"+j);
//								smallWhiteOrderService.doLogisticsProcess(eo);
//								System.out.println("工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-end-"+j);
//							}
//						});
//					}
//				} catch (Exception e) {
//					e.printStackTrace();
//				}finally {
//					executorService.shutdown();
//				}

//				ExecutorService executorService1 = Executors.newCachedThreadPool();
//				try {
//					for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {
//						final int j = i;
//						executorService1.execute(new Runnable() {
//							@Override
//							public void run() {
//								Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(j);
//								EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
//								//代理商订单推送发货状态
//								System.out.println("工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-start-"+j);
////								eshopOrderService.pushDeliveryStatusToAgents(eo);
//								try {
//									Thread.sleep(10000);
//								} catch (InterruptedException e) {
//									e.printStackTrace();
//								}
//								System.out.println("工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-end-"+j);
//							}
//						});
//					}
//				} catch (Exception e) {
//					e.printStackTrace();
//				}finally {
//					executorService1.shutdown();
//				}

                //尝试异步
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {
                            Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(i);
                            EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
                            //自动流转发货
                            System.out.println(eo.getOrderId()+":工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-start-"+i);
                            smallWhiteOrderService.doLogisticsProcess(eo);
                            System.out.println(eo.getOrderId()+":工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-end-"+i);
                        }
                    }
                }).start();

//				for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {
//					Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(i);
//					EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
//					//自动流转发货
//					System.out.println("工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-start-" + i);
////					smallWhiteOrderService.doLogisticsProcess(eo);
//					System.out.println("工作流语句:自动流转发货smallWhiteOrderService.doLogisticsProcess(eo)-end-" + i);
//				}

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < xbOrderToDeliveryList.size(); i++) {
                            Map<String, Object> deliveryMap = xbOrderToDeliveryList.get(i);
                            EshopOrder eo = eshopOrderService.getEntityById(deliveryMap.get("ORDER_ID").toString());
                            //代理商订单推送发货状态
                            System.out.println(eo.getOrderId()+":工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-start-"+i);
                            eshopOrderService.pushDeliveryStatusToAgents(eo);
                            System.out.println(eo.getOrderId()+":工作流语句:代理商订单推送发货状态eshopOrderService.pushDeliveryStatusToAgents(eo)-end-"+i);
                        }
                    }
                }).start();


                System.out.println("批量发货工作流结束 返回success");
            }
        }
        if(flag) {
            deliveryjsonArray = JSONArray.fromObject(xbOrderToDeliveryList);

            if (logisticsAgentsId.equals("17")) {
                return "JD_dispatchPrint";


            } else if (logisticsAgentsId.equals("16")) {
                return "EMS_dispatchPrint";
            }
            return "JD_dispatchPrint";
        }
        return ERROR;
    }

    */
/**
     * 小白订单批量发货历史查询
     * @return
     *//*

    public String batchXBSendOrderHistory(){
        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("batchXBSendOrderInfo=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        String adminCompanyIdStr=eshopAdmin.getCompanyIdStr();
        if(StringUtil.isBlank(adminCompanyIdStr)){
            Log4jUtil.interfaceLogger.info(adminId+"未获取到厂商信息");
            msg=adminId+"未获取到厂商信息";
            return ERROR;
        }
        xbSenderHistoryList = new ArrayList<SmallWhiteBatchSenderHistoryInfo>();
        List<String> batchIdHistoryList = eshopOrderService.batchIdHistory(String.valueOf(adminId),"7");
        System.out.println("adminId="+adminId+"::batchIdHistoryList="+batchIdHistoryList.size());
        if(null != batchIdHistoryList && 0<batchIdHistoryList.size()){
            for(String batchId : batchIdHistoryList){
                List<Map<String, Object>> mapList = eshopOrderService.findBybatchId(batchId);
                if(null != mapList && 0<mapList.size()) {
                    SmallWhiteBatchSenderHistoryInfo smallWhiteBatchSenderHistoryInfo = new SmallWhiteBatchSenderHistoryInfo();
                    smallWhiteBatchSenderHistoryInfo.setBatchId(batchId);
                    System.out.println("========mapList.get(0)="+mapList.get(0).size());
                    String add_time = mapList.get(0).get("ADD_TIME").toString();
                    System.out.println("======add_time="+add_time);
                    smallWhiteBatchSenderHistoryInfo.setAddTime(add_time);
                    String logisticsAgentsId = mapList.get(0).get("LOGISTICS_AGENTS_ID").toString();
                    smallWhiteBatchSenderHistoryInfo.setLogisticsAgentsId(logisticsAgentsId);
                    String senderSum = String.valueOf(mapList.size());
                    smallWhiteBatchSenderHistoryInfo.setSenderSum(senderSum);
                    String productType = mapList.get(0).get("PRODUCT_TYPE").toString();
                    smallWhiteBatchSenderHistoryInfo.setProductType(productType);
                    String way_name = mapList.get(0).get("WAY_NAME").toString();
                    smallWhiteBatchSenderHistoryInfo.setContentsAttribute(way_name);
                    String add_user = mapList.get(0).get("ADD_USER").toString();
                    smallWhiteBatchSenderHistoryInfo.setAddUser(add_user);
                    String beginOrderId = mapList.get(0).get("ORDER_ID").toString();
                    String beginIccid = "";
                    List<String> iccid1 = eshopOrderService.findIccidByOrderId(beginOrderId);
                    if (null != iccid1 && 0 < iccid1.size()) {
                        beginIccid = iccid1.get(0);
                    }
                    String endOrderId = mapList.get(mapList.size() - 1).get("ORDER_ID").toString();
                    String endIccid = "";
                    List<String> iccid2 = eshopOrderService.findIccidByOrderId(endOrderId);
                    if (null != iccid2 && 0 < iccid2.size()) {
                        endIccid = iccid2.get(0);
                    }
                    smallWhiteBatchSenderHistoryInfo.setIccidInterval(beginIccid + "-" + endIccid);

                    xbSenderHistoryList.add(smallWhiteBatchSenderHistoryInfo);
                }
            }
        }
        return SUCCESS;
    }

    public String seeBatchXBSendOrder(){
        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("batchXBSendOrderInfo=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        String adminCompanyIdStr=eshopAdmin.getCompanyIdStr();
        if(StringUtil.isBlank(adminCompanyIdStr)){
            Log4jUtil.interfaceLogger.info(adminId+"未获取到厂商信息");
            msg=adminId+"未获取到厂商信息";
            return ERROR;
        }
        xbSenderOrderSee = new ArrayList<SmallWhiteBatchSenderHistoryInfo>();
        List<Map<String, Object>> maps = eshopOrderService.seeBatchXBSendOrder(String.valueOf(adminId));
        if(null != maps && 0<maps.size()) {
            for(Map<String, Object> map :maps) {
                SmallWhiteBatchSenderHistoryInfo smallWhiteBatchSenderHistoryInfo = new SmallWhiteBatchSenderHistoryInfo();
                String product_package_name = map.get("PRODUCT_PACKAGE_NAME").toString();
                smallWhiteBatchSenderHistoryInfo.setProductName(product_package_name);
                String product_package_sum = map.get("PRODUCT_PACKAGE_SUM").toString();
                smallWhiteBatchSenderHistoryInfo.setProductNameSum(product_package_sum);
                String can_jd_sum = map.get("CAN_JD_SUM").toString();
                smallWhiteBatchSenderHistoryInfo.setProductCanSendJd(can_jd_sum);
                String can_ems_sum = map.get("CAN_EMS_SUM").toString();
                smallWhiteBatchSenderHistoryInfo.setProductCanSendEms(can_ems_sum);
                xbSenderOrderSee.add(smallWhiteBatchSenderHistoryInfo);
            }
        }
        return SUCCESS;
    }


    */
/**
     * 小白订单批量发货历史明细查询
     * @return
     *//*

    public String batchXBSendOrderView(){
        msg = "";
        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("batchXBSendOrderInfo=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        String adminCompanyIdStr=eshopAdmin.getCompanyIdStr();
        if(StringUtil.isBlank(adminCompanyIdStr)){
            Log4jUtil.interfaceLogger.info(adminId+"未获取到厂商信息");
            msg=adminId+"未获取到厂商信息";
            return ERROR;
        }
        try {
            //通过批次id查询此批发货信息
            List<String> senderInfoList = eshopOrderService.findSenderInfoByBatchId(batchId);
            if (null != senderInfoList && 0 < senderInfoList.size()) {
                StringBuffer senderInfoString = new StringBuffer();
                senderInfoString.append("[");
                for (int i = 0; i < senderInfoList.size(); i++) {
                    String senderInfo = senderInfoList.get(i);
                    senderInfoString.append(senderInfo);
                    if (i != senderInfoList.size() - 1) {
                        senderInfoString.append(",");
                    }
                }
                senderInfoString.append("]");
                deliveryjsonArray = JSONArray.fromObject(senderInfoString.toString());
                System.out.println("=====deliveryjsonArray==="+deliveryjsonArray.size());
            }
        }catch (Exception e){
            e.printStackTrace();
            msg = "历史记录查询异常";
            return ERROR;
        }
        if(logisticsAgentsId != null && ("17".equals(logisticsAgentsId) || "18".equals(logisticsAgentsId))){
            System.out.println("=====JD_dispatchPrint===");
            return "JD_dispatchPrint";
        }else if(logisticsAgentsId != null && "16".equals(logisticsAgentsId)){
            System.out.println("=====EMS_dispatchPrint===");
            return "EMS_dispatchPrint";
        }
        System.out.println("=====SUCCESS===");
        return SUCCESS;
    }

    */
/**
     * 小白订单批量发货批次导出
     * @return
     *//*

    public String xbBatchSenderExport(){
        msg = "";
        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        if(eshopAdmin==null){
            msg="请先进行登录，或确认工号是否正确";
            System.out.println("batchXBSendOrderInfo=="+ eshopAdmin + ":" + msg);
            return ERROR;
        }
        String adminCompanyIdStr=eshopAdmin.getCompanyIdStr();
        if(StringUtil.isBlank(adminCompanyIdStr)){
            Log4jUtil.interfaceLogger.info(adminId+"未获取到厂商信息");
            msg=adminId+"未获取到厂商信息";
            return ERROR;
        }
        try {

            //通过批次id导出此批发货信息
            HttpServletResponse response = ServletActionContext.getResponse();
            //获取输出流
            OutputStream os = response.getOutputStream();
            String fileName = StringUtil.getNow();
            response.reset();
            response.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xls");// 设定输出文件头
            response.setContentType("application/msexcel");// 定义输出类型
            WritableWorkbook wbook = Workbook.createWorkbook(os);// 创建Excel表
            WritableSheet wsheet = wbook.createSheet("小白批量发货批次导出", 0); // sheet名称
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 10,
                    WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,
                    Colour.BLACK);
            // 单元格格式
            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC = new WritableCellFormat(wfont);
            // 设置背景颜色
            wcfFC.setBackground(Colour.YELLOW2);
            // 把水平对齐方式指定为居中
            wcfFC.setAlignment(Alignment.CENTRE);
            // 把垂直对齐方式指定为居中
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);
            int li = 0;
            */
/*订单号、订单下单时间、订单状态、最后一步处理时间、订单发货或者异常处理的处理人。*//*

            wsheet.addCell(new Label(li++, 0, "批次id ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "订单号 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "代理商名称", wcfFC));
            wsheet.addCell(new Label(li++, 0, "下单时间 ", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "预设发展人 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "物流商 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "运单号 ", wcfFC));
            wsheet.addCell(new Label(li++, 0, "京东单号", wcfFC));
            wsheet.addCell(new Label(li++, 0, "小白卡卡号", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "收货人", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "联系电话", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "地址", wcfFC));
            wsheet.addCell(new Label(li++, 0, "商品名称", wcfFC));
            wsheet.addCell(new Label(li++, 0, "省", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "是否可京配", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "终端串码", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "订单总金额", wcfFC));
            //wsheet.addCell(new Label(li++, 0, "终端信息", wcfFC));

            wsheet.setColumnView(0, 30);
            wsheet.setColumnView(1, 30);
            wsheet.setColumnView(2, 30);
            wsheet.setColumnView(3, 30);
            wsheet.setColumnView(4, 30);
            wsheet.setColumnView(5, 30);
            wsheet.setColumnView(6, 30);

            // 设置表内循环样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont);
            wfont = new WritableFont(WritableFont.ARIAL, 11,
                    WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,
                    Colour.BLACK);
            wcfFC2 = new WritableCellFormat(wfont);
            wcfFC2.setWrap(true);

            List<Map<String, String>> senderInfoList = null;
            if(null != batchId && !"".equals(batchId)){
                senderInfoList = eshopOrderService.exportSenderInfoByBatchId(batchId,"7");
            }else {
                senderInfoList = eshopOrderService.exportSenderInfoByBatchId(adminId.toString(),"7");
            }

            int row = 1;
            for (Map<String, String> map : senderInfoList) {
                String batchId = String.valueOf(map.get("BATCHID"));
                String orderId = String.valueOf(map.get("ORDERID"));
                String channelName = String.valueOf(map.get("CHANNELNAME"));
                String createTime = String.valueOf(map.get("CREATETIME"));
                String logisticsAgentsId = String.valueOf(map.get("LOGISTICSAGENTSID"));
                String distributionId = String.valueOf(map.get("DISTRIBUTIONID"));
                String distributionIdMj = map.get("DISTRIBUTIONIDMJ");
                String intelligentCard = String.valueOf(map.get("INTELLIGENTCARD"));
                String receiver = String.valueOf(map.get("RECEIVER"));
                String linkPhone = String.valueOf(map.get("LINKPHONE"));
                String address = String.valueOf(map.get("ADDRESS"));
                String productName = String.valueOf(map.get("PRODUCTNAME"));
                String ifJdSend = String.valueOf(map.get("IFJDSEND"));
                String totalPrice = String.valueOf(map.get("TOTALPRICE"));
                String provinceName = String.valueOf(map.get("PROVINCENAME"));

                int lj = 0;
                wsheet.addCell(new Label(lj++, row, batchId==null?"":batchId , wcfFC2));
                wsheet.addCell(new Label(lj++, row, orderId==null?"":orderId , wcfFC2));
                wsheet.addCell(new Label(lj++, row, channelName==null?"":channelName , wcfFC2));
                wsheet.addCell(new Label(lj++, row, createTime==null?"":createTime , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, "", wcfFC2));
                wsheet.addCell(new Label(lj++, row, logisticsAgentsId==null?"":logisticsAgentsId , wcfFC2));
                wsheet.addCell(new Label(lj++, row, distributionId==null?"":distributionId , wcfFC2));
                wsheet.addCell(new Label(lj++, row, distributionIdMj==null?"":distributionIdMj , wcfFC2));
                wsheet.addCell(new Label(lj++, row, intelligentCard==null?"":intelligentCard , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, receiver==null?"":receiver , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, linkPhone==null?"":linkPhone , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, address==null?"":address , wcfFC2));
                wsheet.addCell(new Label(lj++, row, productName==null?"":productName , wcfFC2));
                wsheet.addCell(new Label(lj++, row, provinceName==null?"":provinceName , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, ifJdSend==null?"":ifJdSend , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, "" , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, totalPrice==null?"":fenToYuan(totalPrice) , wcfFC2));
                //wsheet.addCell(new Label(lj++, row, "", wcfFC2));

                row++;
            }
            wbook.write();//写入文件
            if(wbook != null){
                wbook.close();
            }
            if(os != null){
                os.close();
            }

        }catch (Exception e){
            e.printStackTrace();
            msg = "小白订单批量发货批次导出异常";
            return ERROR;
        }
        return SUCCESS;
    }

    public String batchXBSend() {
        initXiaobaiProductName();
        return SUCCESS;
    }

    public String batchSendOrderQry(){
        System.out.println("*************小白订单批量发货*************");
        initXiaobaiProductName();
        try {
            if (StringUtils.isNotBlank(channel_name)) {
                channel_name = URLDecoder.decode(channel_name, "UTF-8");
                String channelId = eshopOrderService.selectChannelInfo(channel_name);
                if (StringUtils.isNotBlank(channelId)) {
                    channel_id = channelId;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            if (startTime != null && !startTime.equals("")) {
                startDate = StringUtil.stringToUtilDate(startTime.trim()
                        + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
            }
            if (endTime != null && !endTime.equals("")) {
                endDate = StringUtil.stringToUtilDate(endTime.trim()
                        + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String ifSendJd = "";
        if (null != if_send_jd && !StringUtil.empty(if_send_jd)) {
            if("1".equals(if_send_jd) || "Y".equals(if_send_jd)){
                ifSendJd = "Y";
            }else if("2".equals(if_send_jd) || "N".equals(if_send_jd)){
                ifSendJd = "N";
            }
        }
        if_send_jd = ifSendJd;

        String ifSendEms = "";
        if (null != if_send_ems && !StringUtil.empty(if_send_ems)) {
            if("2".equals(if_send_ems) || "Y".equals(if_send_ems)){
                ifSendEms = "Y";
            }else if("3".equals(if_send_ems) || "N".equals(if_send_ems)){
                ifSendEms = "N";
            }
        }
        if_send_ems = ifSendEms;

        ps = eshopOrderService.batchSendOrderQry(this);
        totalCount = ps.getTotalCount();

        return SUCCESS;

    }

    */
/***************************************************************************
     * 初始化小白产品类型、渠道名
     **************************************************************************//*

    private void initXiaobaiProductName(){
        productNameInfoMap=new TreeMap<String, String>();
        channelNameInfoMap = new TreeMap<String, String>();
        pubCodeInfoMap = new TreeMap<String, String>();
        eshopAdmin = Cantants.getEshopAdmin();
        Long adminId = eshopAdmin.getAdminId();
        String s = String.valueOf(adminId);
        String assignee_ = "TO_DELIVERY"+s;
        String companyIdStr = eshopAdmin.getCompanyIdStr();
        List<Map<String, String>> xbSendProductNameList = eshopOrderService.selectXBSendProductName(assignee_, companyIdStr);
        System.out.println("=======xbSendProductNameList.size()"+xbSendProductNameList.size());
        if(xbSendProductNameList.size()>0){
            for(int i=0 ; i < xbSendProductNameList.size() ; i++){
                Map<String, String> stringMap = xbSendProductNameList.get(i);
                String product_name = stringMap.get("PRODUCT_NAME");
                System.out.println("======product_name="+product_name);
                productNameInfoMap.put(product_name,product_name);
                String channel_name = stringMap.get("CHANNEL_NAME");
                channelNameInfoMap.put(channel_name,channel_name);
                String pub_code = stringMap.get("PUB_CODE");
                pubCodeInfoMap.put(pub_code,pub_code);
            }
        }
    }

    public String checkIfSendJd(){
        try {
            if(StringUtil.isNotBlank(chooseParams)){
                String canNotSendJd = eshopOrderService.checkIfSendJd(chooseParams);
                if(StringUtil.isNotBlank(canNotSendJd)){
                    message = "存在不可京配订单:"+canNotSendJd;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            message = "校验订单是否可京配异常！";
        }
        return SUCCESS;
    }
    public String checkIfSendEms(){
        try {
            if(StringUtil.isNotBlank(chooseParams)){
                String canNotSendEms = eshopOrderService.checkIfSendEms(chooseParams);
                if(StringUtil.isNotBlank(canNotSendEms)){
                    message = "存在不可EMS配送订单:"+canNotSendEms;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            message = "校验订单是否可EMS配送异常！";
        }
        return SUCCESS;
    }

    public String selectCanSendSum(){
        now_actual_send_sum = "";
        try {
            if(StringUtil.isNotBlank(product_name)){
                product_name = URLDecoder.decode(product_name, "UTF-8");
            }
            if(StringUtil.isNotBlank(send_num) && StringUtil.isNotBlank(product_name) && StringUtil.isNotBlank(logisticsAgentsId)){
                eshopAdmin = Cantants.getEshopAdmin();
                Long adminId = eshopAdmin.getAdminId();
                if (eshopAdmin == null) {
                    msg = "请先进行登录，或确认工号是否正确";
                    System.out.println("batchXBSendOrderInfo==" + eshopAdmin + ":" + msg);
                    return ERROR;
                }
                String adminCompanyIdStr = eshopAdmin.getCompanyIdStr();
                if (StringUtil.isBlank(adminCompanyIdStr)) {
                    Log4jUtil.interfaceLogger.info(adminId + "未获取到厂商信息");
                    System.out.println(adminId + "未获取到厂商信息");
                    msg = adminId + "未获取到厂商信息";
                    return ERROR;
                }
                String assignee_ = "";
                if (null != adminCompanyIdStr && !StringUtil.empty(adminCompanyIdStr)) {
                    assignee_ = "TO_DELIVERY" + adminId + "%";
                }

                List<Map<String, Object>> maps = eshopOrderService.selectCanSendSum(assignee_, adminCompanyIdStr, send_num, product_name, logisticsAgentsId);
                if(null != maps && 0 < maps.size()){
                    int size = maps.size();
                    String s = String.valueOf(size);
                    if(Integer.parseInt(send_num) > size){
                        if("17".equals(logisticsAgentsId)){
                            now_actual_send_sum = "当前商品可京配数量不足"+send_num+"单，当前满足条件的订单："+s+"单";
                        }else if("16".equals(logisticsAgentsId)){
                            now_actual_send_sum = "当前商品可EMS配送数量不足"+send_num+"单，当前满足条件的订单："+s+"单";
                        }
                    }
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
            now_actual_send_sum = "校验实际可配送订单异常！";
        }
        return SUCCESS;
    }

    private String getSeqStr(String prex, String dateformate, int randnum) {
        if (dateformate == null) {
            dateformate = "yyMMddHHmmss";
        }
        Date date = new Date();
        String datetime = DateUtil.date2Str(date, dateformate);
        String randStr = RandomStringUtils.randomNumeric(randnum);
        return (prex + datetime + randStr).trim();
    }


    public File getUpfile() {
        return upfile;
    }

    public void setUpfile(File upfile) {
        this.upfile = upfile;
    }

    public String getUpfileFileName() {
        return upfileFileName;
    }

    public void setUpfileFileName(String upfileFileName) {
        this.upfileFileName = upfileFileName;
    }

    public String getUpfileContentType() {
        return upfileContentType;
    }

    public void setUpfileContentType(String upfileContentType) {
        this.upfileContentType = upfileContentType;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getInputPath() {
        return inputPath;
    }

    public void setInputPath(String inputPath) {
        this.inputPath = inputPath;
    }

    public InputStream getInputStream() {
        return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getExternalOrderId() {
        return externalOrderId;
    }

    public void setExternalOrderId(String externalOrderId) {
        this.externalOrderId = externalOrderId;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getLinkPhone() {
        return linkPhone;
    }

    public void setLinkPhone(String linkPhone) {
        this.linkPhone = linkPhone;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public PaginationSupport getPs() {
        return ps;
    }

    public void setPs(PaginationSupport ps) {
        this.ps = ps;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getPubCode() {
        return pubCode;
    }

    public void setPubCode(String pubCode) {
        this.pubCode = pubCode;
    }

    public String getCheckFlag() {
        return checkFlag;
    }

    public void setCheckFlag(String checkFlag) {
        this.checkFlag = checkFlag;
    }

    public String getTemplateUrl() {
        return templateUrl;
    }

    public void setTemplateUrl(String templateUrl) {
        this.templateUrl = templateUrl;
    }

    public String getLogisticsAgentsId() {
        return logisticsAgentsId;
    }

    public void setLogisticsAgentsId(String logisticsAgentsId) {
        this.logisticsAgentsId = logisticsAgentsId;
    }

    public String getSend_num() {
        return send_num;
    }

    public void setSend_num(String send_num) {
        this.send_num = send_num;
    }

    public String getProductType() {
        return productType;
    }

    public void setProductType(String productType) {
        this.productType = productType;
    }

    public String getContentsAttribute() {
        return contentsAttribute;
    }

    public void setContentsAttribute(String contentsAttribute) {
        this.contentsAttribute = contentsAttribute;
    }

    public String getICCIDStart() {
        return ICCIDStart;
    }

    public void setICCIDStart(String ICCIDStart) {
        this.ICCIDStart = ICCIDStart;
    }

    public String getICCIDEnd() {
        return ICCIDEnd;
    }

    public void setICCIDEnd(String ICCIDEnd) {
        this.ICCIDEnd = ICCIDEnd;
    }

    public List<Map<String, Object>> getXbOrderToDeliveryList() {
        return xbOrderToDeliveryList;
    }

    public void setXbOrderToDeliveryList(List<Map<String, Object>> xbOrderToDeliveryList) {
        this.xbOrderToDeliveryList = xbOrderToDeliveryList;
    }
    public List<SmallWhiteBatchSenderHistoryInfo> getXbSenderHistoryList() {
        return xbSenderHistoryList;
    }

    public void setXbSenderHistoryList(List<SmallWhiteBatchSenderHistoryInfo> xbSenderHistoryList) {
        this.xbSenderHistoryList = xbSenderHistoryList;
    }

    public String getBatchId() {
        return batchId;
    }

    public void setBatchId(String batchId) {
        this.batchId = batchId;
    }

    public JSONArray getDeliveryjsonArray() {
        return deliveryjsonArray;
    }

    public void setDeliveryjsonArray(JSONArray deliveryjsonArray) {
        this.deliveryjsonArray = deliveryjsonArray;
    }

    public Map<String, String> getProductNameInfoMap() {
        return productNameInfoMap;
    }

    public void setProductNameInfoMap(Map<String, String> productNameInfoMap) {
        this.productNameInfoMap = productNameInfoMap;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getProduct_name() {
        return product_name;
    }

    public void setProduct_name(String product_name) {
        this.product_name = product_name;
    }

    public EshopAdmin getEshopAdmin() {
        return eshopAdmin;
    }

    public void setEshopAdmin(EshopAdmin eshopAdmin) {
        this.eshopAdmin = eshopAdmin;
    }

    public String getChooseSum() {
        return chooseSum;
    }

    public void setChooseSum(String chooseSum) {
        this.chooseSum = chooseSum;
    }

    public String getChooseParams() {
        return chooseParams;
    }

    public void setChooseParams(String chooseParams) {
        this.chooseParams = chooseParams;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public String getIf_send_jd() {
        return if_send_jd;
    }

    public void setIf_send_jd(String if_send_jd) {
        this.if_send_jd = if_send_jd;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getIf_send_ems() {
        return if_send_ems;
    }

    public void setIf_send_ems(String if_send_ems) {
        this.if_send_ems = if_send_ems;
    }

    public String getNow_actual_send_sum() {
        return now_actual_send_sum;
    }

    public void setNow_actual_send_sum(String now_actual_send_sum) {
        this.now_actual_send_sum = now_actual_send_sum;
    }

    public Map<String, String> getChannelNameInfoMap() {
        return channelNameInfoMap;
    }

    public void setChannelNameInfoMap(Map<String, String> channelNameInfoMap) {
        this.channelNameInfoMap = channelNameInfoMap;
    }

    public Map<String, String> getPubCodeInfoMap() {
        return pubCodeInfoMap;
    }

    public void setPubCodeInfoMap(Map<String, String> pubCodeInfoMap) {
        this.pubCodeInfoMap = pubCodeInfoMap;
    }

    public String getChannel_name() {
        return channel_name;
    }

    public void setChannel_name(String channel_name) {
        this.channel_name = channel_name;
    }

    public String getChannel_id() {
        return channel_id;
    }

    public void setChannel_id(String channel_id) {
        this.channel_id = channel_id;
    }

    public List<SmallWhiteBatchSenderHistoryInfo> getXbSenderOrderSee() {
        return xbSenderOrderSee;
    }

    public void setXbSenderOrderSee(List<SmallWhiteBatchSenderHistoryInfo> xbSenderOrderSee) {
        this.xbSenderOrderSee = xbSenderOrderSee;
    }

    public String getLsjg() {
        return lsjg;
    }

    public void setLsjg(String lsjg) {
        this.lsjg = lsjg;
    }

    public String getYsr() {
        return ysr;
    }

    public void setYsr(String ysr) {
        this.ysr = ysr;
    }

    public static void main(String[] args) throws Exception{
//		SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		System.out.println(sdf1.format(new Date()));
//		TimeZone zone = TimeZone.getTimeZone("GMT");
//		sdf1.setTimeZone(zone);
//		System.out.println(sdf1.format(new Date()));

        SmallWhiteOrderServiceImpl smallWhiteOrderServiceImpl = new SmallWhiteOrderServiceImpl();
//
//		Long startTime = System.currentTimeMillis();
//		for(int a = 100;a>0;a--){
        smallWhiteOrderServiceImpl.checkIfJdSend("202104060446999","山东济南市天桥区无影山街道 鑫苑碧水");
//		}
//		Long endTime = System.currentTimeMillis();
//		System.out.println(endTime-startTime);
//		Map map1 = new HashMap();
//		map1.put("a","a");
//		map1.put("b","b");
//		map1.put("c","c");
//		Map map2 = new HashMap();
//		map2.put("a","a");
//		map2.put("b","b");
//		map2.put("c","c");
//		List list = new ArrayList();
//		list.add(map1);
//		list.add(map2);
//		System.out.println(JSONObject.fromObject(map1));
//		System.out.println(list.toString());
//		System.out.println(JSONArray.fromObject(list));

//		String s = "{slideNo=21, PROVINCENAME=测试单, senderAddress=北京市海淀区北四环中路229号海泰大厦, sourceSortCenterName=北京大兴分拣中心, RECEIVER=测试, ADDRESS=河北邯郸市涉县无, iccid=8986032076010813452, sourceTabletrolleyCode=112-D7, road=001, CHANNEL_NAME=北京合智源科技开发有限责任公司, LINK_PHONE=15732612169, productType=1, distributionId=JD210309416338, ORDER_ID=100000003053512, ORDER_ITEM_ID=100000003333797, senderName=北京电信, sourceCrossCode=21, senderPhone=4008981189, targetTabletrolleyCode=W15, targetSortCenterName=北京魏永分拣中心, siteName=*北京装甲兵工程学院京东派}";
//		System.out.println(JSONArray.fromObject(s));
    }
    */
/**
     * 分转换为元
     * @param fen
     * @return
     *//*

    public static String fenToYuan(String fen){
        String yuan = "";
        System.out.println("fen.trim()"+fen.trim());
        if (fen == null || "".equals(fen.trim()) || ".".equals(fen.trim()) || "0".equals(fen.trim())){
            return "0";
        }
        BigDecimal f = new BigDecimal(fen.trim());
        BigDecimal m = new BigDecimal("100");
        yuan = f.divide(m, 2, BigDecimal.ROUND_DOWN).toString();
        return removeNumZero(yuan);
    }
    public static String removeNumZero(String s){
        if(s.charAt(0) == '.'){
            s = "0" + s;
        }
        if(s.charAt(0) == '0' && !"0".equals(s)){
            DecimalFormat df = new DecimalFormat("0.000000");
            s = df.format(Double.valueOf(s));
        }
        if ("0".equals(s) || "0.0".equals(s)){
            return "0";
        }
        return removeTailZero(s);
    }
    private static String removeTailZero(String s){
        int len = 0;
        len = s.length();
        for(int ii = 0; ii < len; ii++){
            if (s.charAt(ii) == '0' && s.charAt(ii + 1) != '.'){
                s = s.substring(ii + 1);
                removeTailZero(s);
            }else{
                break;
            }
        }
        if(s.indexOf('.') >= 0){
            len = s.length();
            for(int ii = len - 1; ii >= 0; ii--){
                if (s.charAt(ii) == '0'){
                    s = s.substring(0, ii);
                    removeTailZero(s);
                }else{
                    break;
                }
            }
            len = s.length();
            if (s.charAt(len - 1) == '.'){
                s = s.substring(0, len - 1);
            }
        }
        return s;
    }
}
*/
